Fix empty query/fragment. Add more tests.

Note that empty query/fragment is not equivalent
to null query/fragment.