Correctly get the base path of uris with a query string

And add a test. :)