Skip to content

Instantly share code, notes, and snippets.

@gruis
Forked from pwim/gist:1188099
Created February 16, 2012 01:06
Show Gist options
  • Save gruis/1840492 to your computer and use it in GitHub Desktop.
Save gruis/1840492 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