Skip to content

Instantly share code, notes, and snippets.

@ZenCocoon
Created September 26, 2010 17:09
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 ZenCocoon/598114 to your computer and use it in GitHub Desktop.
Save ZenCocoon/598114 to your computer and use it in GitHub Desktop.
def url_escape(string)
string.gsub(/([^ ;\/?:@=#&a-zA-Z0-9_.-]+)/n) do
'%' + $1.unpack('H2' * $1.size).join('%').upcase
end.tr(' ', '+')
end
@ZenCocoon
Copy link
Author

Ideal to encode URL with utf8 characters while keeping URL Specific Characters as is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment