Fix parsing of root URIs

Also add a test to ensure this doesn't break in the future.