Skip to content

Instantly share code, notes, and snippets.

@dgdavid
Last active August 31, 2021 13:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgdavid/1e662b81c100c1cced3c33a61075bb57 to your computer and use it in GitHub Desktop.
Save dgdavid/1e662b81c100c1cced3c33a61075bb57 to your computer and use it in GitHub Desktop.

URI.unescape is obsolete

https://ruby-doc.org/stdlib-2.7.1/libdoc/uri/rdoc/URI/Escape.html#method-i-unescape-label-Description

This method is obsolete and should not be used. Instead, use CGI.unescape, URI.decode_www_form or URI.decode_www_form_component depending on your specific use case.

URI.unescape

fake_escaped_url = "/%40%23%24%25%5e%26/dir/%c4%8d%c3%bd%c4%9b%c5%a1%c4%8d%c3%bd%c3%a1/file"
URI.unescape(fake_escaped_url)
# => "/@\#$%^&/dir/čýěščýá/file"

URI.decode_www_form

fake_escaped_url = "/%40%23%24%25%5e%26/dir/%c4%8d%c3%bd%c4%9b%c5%a1%c4%8d%c3%bd%c3%a1/file"
URI.decode_www_form(fake_escaped_url)
# => [["/@\#$%^&/dir/čýěščýá/file", ""]]

URI.decode_www_form_component

fake_escaped_url = "/%40%23%24%25%5e%26/dir/%c4%8d%c3%bd%c4%9b%c5%a1%c4%8d%c3%bd%c3%a1/file"
URI.decode_www_form_component(fake_escaped_url)
# => "/@\#$%^&/dir/čýěščýá/file"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment