Improve query string handling. 

* Add objectToQuery and queryToObject.
* Start replacing fragile URL query string manipulation with those functions.
* Fix specs that incorrectly depended on exact URL string equality, and other spec cleanup.

Fixes #2165
Is there a reason why you use an array and then `join` rather than building a string as you go?  I thought maybe join was faster, but this post seems to think otherwise: http://stackoverflow.com/questions/7299010/why-is-string-concatenation-faster-than-array-join I'm not sure if this code is ever performance critical, so it may not matter anyway.