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.

又土鳖了一把

更新: [gitmo](http://www.aasii.org/download/gitmo) 已经过期了,Sergey Yanovich 更新了 [git repo](http://repo.or.cz/w/mozilla-1.9.git) 上的说明,现在应该用这个 [client.sh](http://www.aasii.org/download/client.sh) 来更新。

今天实在是受不了 CVS 了:在 mozilla 这么大的树上用 cvs diff 简直是自虐,于是找来 mozilla cvs trunk 的 [git mirror](http://repo.or.cz/w/mozilla-1.9.git/) 来 clone,上次 clone 过一次发现缺东西不能编译,因为 mozilla cvs 树里有些东西是作为 external item 放在别的地方的,比如 nsprpub,但 git mirror (和 [hg mirror](http://hg.mozilla.org/cvs-trunk-mirror)) 都没有镜像这些。

因为看 [mozilla.dev.platform](http://groups.google.com/group/mozilla.dev.platform) 上[有人贴了](http://groups.google.com/group/mozilla.dev.platform/browse_thread/thread/8918d92bd3ba7694)一个 [gitmo](http://www.aasii.org/download/gitmo) 的脚本还方便,以为不会出问题的,结果还是出问题了。

为什么呢?因为 git 的 mirror 是用那个 repository 的几个 branch 来存这些 external items 的,每次我要用到这些 external items 来编译的时候,就把 checkout -b 一个 本地的 branch 出来,remote 的一个 branch 给 merge 进来,然后编译,问题是这些个 remote branch 的镜像更新似乎不如 CVS 上的勤,结果跟主干上的代码就不一致了。

虽然归根结地还是 mozilla 土鳖:CVS 这种原始社会的玩意早该淘汰了,但经验之谈是:除非对 Mozilla 的代码树结构以及它的编译系统很熟悉,否则如果自己要编译 Firefox 还是[直接从 CVS 上取](http://developer.mozilla.org/en/docs/Mozilla_Source_Code_Via_CVS)最省事,出问题的概率最小。

哦,顺便说一句,最近解决了一个 Firefox 3 在 Mac OS X 10.5 上的一个比较严重的 [bug](https://bugzilla.mozilla.org/show_bug.cgi?id=408965),涉及中文字体的载入和顺序,patch 已经进入主干,最新的 nightly build 中也已经包含,不妨试试。