How to test a proxy autoconfiguration file

Due to the existence of Greal Firewall, I have a terribly long proxy.pac file. Apparently, how to maintain that becomes a problem. Regularly, I use git 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, which turned out to be very useful. Basically it’s a Perl wrap of 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.

Pro JavaScript Techniques 的中文版上市

相信熟悉 Web 设计的朋友已经了解,这本书是一本关于 JavaScript 的较有深度的书籍,中文版是由贤安 (realazy) 和我一起翻译的,中文译名是《精通 JavaScript》。

原书的价值,对于熟悉的朋友应该毋庸置疑,我们两人在翻译时也颇费了一番功夫,大致分工是我主要负责和语言特性相关的,贤安主要负责和 Web 应用相关的 (包括与 CSS 的配合),如果有任何意见建议,欢迎致信 projsch@gmail.com,我们会将所有的更正与改进放在勘误页面上。