Write a test, because sometimes you are a moron.

The other day I was working with Javascript and regexes:

var url='http://www.example.com/path?parameter=value+with+old+school+spaces';
reg = /+/g; 
alert(url.replace(reg,'%2B'));

I spent a good 15 minutes trying to figure out why this wasn’t working… Actually, it does work, but because when you display anything in an alert window, it all gets decoded. So, my first attempt was correct, I just couldn’t see it. I guess the point is, write a repeatable test, don’t just do adhoc testing.

Stay tuned, I’ll soon talk to you about the wonderful world of URL/URI entity encoding.

Leave a Reply