Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@michaeleconomy
Created September 27, 2012 20:53
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 michaeleconomy/3796400 to your computer and use it in GitHub Desktop.
Save michaeleconomy/3796400 to your computer and use it in GitHub Desktop.
Fix for ascii-8bit chars making it in as keys in params
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