process_uri: only encode if invalid

This resolves #999 and is a step in the right direction for #733.

Instead of just blindly unescaping and then escaping uris, which breaks on uri-encoded characters that are permitted in uris like "+" (aka "%2B") or "[" aka "%5B", we're only escaping uris if they aren't already valid. 

This pull doesn't let us support urls like 'http://example.com/].jpg', because URI.encode doesn't touch brackets (they're valid in 'http://example.com/?foo[]=bar'). If it's important to someone that we support those, I'll leave that to someone braver than I.