Skip to content

Instantly share code, notes, and snippets.

@pwim
Created September 2, 2011 07:34
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pwim/1188099 to your computer and use it in GitHub Desktop.
Save pwim/1188099 to your computer and use it in GitHub Desktop.
Trying different encodings under Ruby 1.9
escaped = CGI.unescape(query)
return escaped if escaped.valid_encoding?
%w[EUC-JP Shift_JIS].each do |encoding|
s = escaped.force_encoding(encoding)
return s.encode("UTF-8") if s.valid_encoding?
end
escaped
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment