How to test a proxy autoconfiguration file

Due to the existence of [Greal Firewall](en.wikipedia.org/wiki/Golden_Shield_Project), I have a terribly long `proxy.pac` file. Apparently, how to maintain that becomes a problem. Regularly, I use [git](http://git-scm.com) to keep a “stable” version and make updates on it.

Recently I just found the script stop working for no good reason, because the proxy server I’m using is working, and I tried manually choose a proxy server (by entering its address and port into my browser directly) it also worked, so apparently there is something wrong with the script.

However, it has been a while since I last commit my changes to this script back to git. So there are some changes I wish to keep and I don’t want to do a binary search to find out the problem (Yep, I’m a lazy guy).

A few googling got me a tool called [pactester](http://code.google.com/p/pactester/), which turned out to be very useful. Basically it’s a Perl wrap of [SpiderMonkey](http://www.mozilla.org/js/spidermonkey) JavaScript engine. Since the proxy autoconfiguration script is just a subset of plain JavaScript, it can safely executes that with SpiderMonkey and find out where is the problem.

So I installed it and did one test:

$ pactester -p ~/Documents/Miscs/proxy.pac -u ‘http://blog.iphone-dev.org’
Use of uninitialized value in numeric ne (!=) at pactester line 137.
Error: SyntaxError: missing ) after condition at line 98:
if (dnsDomainIs(host, “cubes.fr”) return “SOCKS 127.0.0.1:7777”;

So that’s the problem. Fixed it, everything is back to normal again!

That’s a small tip on debugging a complex pac script, hope it helps.