instance method normalize_encode_params

Ruby on Rails 4.1.16

Since v4.0.13 Last seen in v4.2.9 Private

Available in: v4.0.13 v4.1.16 v4.2.9

Signature

normalize_encode_params(params)

Convert nested Hash to HashWithIndifferentAccess and UTF-8 encode both keys and values in nested Hash.

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

Parameters

params req
Source
# 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

Defined in actionpack/lib/action_dispatch/http/parameters.rb line 59 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActionDispatch::Http::Parameters

Type at least 2 characters to search.

↑↓ navigate · open · esc close