Handle unicode content in the uri module properly

Fixes #5869