Fix handling of incorrectly encoded URIs