TODO: Validate that the characters are UTF-8. If they aren’t, you’ll
get a weird error down the road, but our form handling should really
prevent that from happening
# File actionpack/lib/action_dispatch/http/parameters.rb, line 59
def normalize_encode_params(params)
case params
when String
params.force_encoding(Encoding::UTF_8).encode!
when Hash
if params.has_key?(:tempfile)
UploadedFile.new(params)
else
params.each_with_object({}) do |(key, val), new_hash|
new_key = key.is_a?(String) ? key.dup.force_encoding(Encoding::UTF_8).encode! : key
new_hash[new_key] = if val.is_a?(Array)
val.map! { |el| normalize_encode_params(el) }
else
normalize_encode_params(val)
end
end.with_indifferent_access
end
else
params
end
end