Tests and a fix for URL parsing and building

Just a small patch to add an initial unit test (not meant to be complete) for URL parsing and building, and a minor bugfix