Skip to content

Instantly share code, notes, and snippets.

@dylanjha dylanjha/uri-encoding.md
Last active Oct 3, 2018

Embed
What would you like to do?

Inconsistent uri encoding with parenthesis. Notice in the first 3 examples the parenthesis are still there, in the fourth example the parenthesis are replaced with %28 and %29:

This is the string being encoded in each example: www.google.com?q=some string with (parens)

===

Javascript (node 6.9.0):

encodeURI("www.google.com?q=some string with (parens)")
// > www.google.com?q=some%20string%20with%20(parens)

Ruby 2.3.0 - URI library

require('uri')
URI.encode("www.google.com?q=some%20string%20with%20(parens)")
# > "www.google.com?q=some%2520string%2520with%2520(parens)" 

Ruby 2.3.0 - Open URI library

require('open-uri')
URI.encode("www.google.com?q=some%20string%20with%20(parens)")
# > "www.google.com?q=some%2520string%2520with%2520(parens)" 

Ruby 2.3.0 - ERB::Util

require('erb')
ERB::Util.url_encode("www.google.com%3Fq%3Dsome%2520string%2520with%2520%28parens%29")
# > "www.google.com%3Fq%3Dsome%2520string%2520with%2520%28parens%29"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.