I suggest to use the node.js URL parser rather than handcrafting one ourselves:

http://nodejs.org/api/url.html

I think this solution is more future proof with respect to random future changes of specification.