Patch for param parsing to check for encoded latin-1 URL parameters
# | |
# Source: https://rails.lighthouseapp.com/projects/8994/tickets/2188-i18n-fails-with-multibyte-strings-in-ruby-19-similar-to-2038 | |
# (fix_params.rb) | |
module ActionController | |
class Request | |
private | |
def check_string_encoding(str) | |
str.valid_encoding? ? str : str.force_encoding("iso-8859-1").encode("utf-8") | |
end | |
# Convert nested Hashs to HashWithIndifferentAccess and replace | |
# file upload hashs with UploadedFile objects | |
def normalize_parameters(value) | |
case value | |
when Hash | |
if value.has_key?(:tempfile) | |
upload = value[:tempfile] | |
upload.extend(UploadedFile) | |
upload.original_path = value[:filename] | |
upload.content_type = value[:type] | |
upload | |
else | |
h = {} | |
value.each { |k, v| h[k] = normalize_parameters(v) } | |
h.with_indifferent_access | |
end | |
when Array | |
value.map { |e| normalize_parameters(e) } | |
else | |
value.force_encoding(Encoding::UTF_8) | |
check_string_encoding(value) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment