Created
September 27, 2012 20:53
-
-
Save michaeleconomy/3796400 to your computer and use it in GitHub Desktop.
Fix for ascii-8bit chars making it in as keys in params
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActionDispatch | |
module Http | |
module Parameters | |
private | |
def encode_params(params) | |
return params unless "ruby".encoding_aware? | |
if params.is_a?(String) | |
return params.force_encoding("UTF-8").encode! | |
elsif !params.is_a?(Hash) | |
return params | |
end | |
h = {} | |
params.each do |k, v| | |
h[encode_params(k.dup)] = | |
case v | |
when Hash | |
encode_params(v) | |
when Array | |
v.map! {|el| encode_params(el) } | |
else | |
encode_params(v) | |
end | |
end | |
h | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment