April 6, 2008 by Noah
I feel like going on a mini rant about JavaScript.

When I built the new content management system, I wanted to program in automatic obfuscation of e-mail addresses. So, from the source pages the e-mails could be written out in plain old HTML (a href=""), and the CMS would automatically encode that to be href="/?p=contact;who=zlanzr+abjurer.arg". Essentially, this makes the link not appear to be an e-mail link at all, so spam harvesters can't find it very easily. JavaScript could change it back, and users without JavaScript would follow the link as-is where they could be greeted with an HTML form to send e-mail without revealing the address in plain text.

So, a JavaScript runs on the browser to translate that URL back into a perfectly valid e-mail link. The e-mail address is encoded as ROT13, and I was using a function I found on the Internet that would decode it for me. Only, the person who wrote the code is a total n00b.

Before dealing with this new method of e-mail obfuscation, I had a script I made that would automatically loop through all the hyperlinks on the page, changing off-site links to open in new windows for example. I took this stuff out when I added the JavaScript that would decode Starburst's encoded e-mail links. When I went to add my old code back in, it conflicted with the ROT13 code.

Basically, the main loop on the ROT13 code didn't declare the variable "i" in a local scope, so it was overwriting the "i" used in the main hyperlink loop, ending up with my code getting stuck in an infinite loop. Also, when it came to actually translating the ROT13, it was treating the alphabet as numbers (i.e. "C > A and C < Z"), which, I'm partly surprised JavaScript even allows that but it was also painful to read as a programmer who knows how horrible that is. It took some digging but I ended up having to write my own ROT13 functions which would translate the letters into their decimal counterparts, then compare them as numbers before translating them back. Much more efficient.

I generally don't like to use other peoples JavaScript codes, and this is a fine example of why. The ridiculously poor coding style of this script was messing my stuff up and causing all kinds of problems. Anyway, end of rant.



There are 0 comments on this page. Add yours.

Add a Comment

Used for your Gravatar and optional thread subscription. Privacy policy.
You may format your message using GitHub Flavored Markdown syntax.