Harden toUri/toUrl methods.