Skip to content

Instantly share code, notes, and snippets.

@dylanjha
Last active October 3, 2018 13:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dylanjha/d7c9da08dd407430f70dbf0fefb00571 to your computer and use it in GitHub Desktop.
Save dylanjha/d7c9da08dd407430f70dbf0fefb00571 to your computer and use it in GitHub Desktop.

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