From e5945e49653e38f4df445284eafda6fa288f071b Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Mon, 19 Aug 2013 15:17:11 -0300 Subject: Organize normalize_encoding_params' conditionals a bit better and use a case statement for it Refactor of the work done in #11891 --- actionpack/lib/action_dispatch/http/parameters.rb | 33 ++++++++++++----------- 1 file changed, 18 insertions(+), 15 deletions(-) (limited to 'actionpack/lib/action_dispatch') diff --git a/actionpack/lib/action_dispatch/http/parameters.rb b/actionpack/lib/action_dispatch/http/parameters.rb index 8e46441d24..ca10da702c 100644 --- a/actionpack/lib/action_dispatch/http/parameters.rb +++ b/actionpack/lib/action_dispatch/http/parameters.rb @@ -57,24 +57,27 @@ module ActionDispatch # you'll get a weird error down the road, but our form handling # should really prevent that from happening def normalize_encode_params(params) - if params.is_a?(String) - return params.force_encoding(Encoding::UTF_8).encode! - elsif Hash === params && params.has_key?(:tempfile) - return UploadedFile.new(params) - elsif !params.is_a?(Hash) - return params - end - - new_hash = {} - params.each do |key, val| - 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) } + case params + when String + params.force_encoding(Encoding::UTF_8).encode! + when Hash + if params.has_key?(:tempfile) + UploadedFile.new(params) else - normalize_encode_params(val) + new_hash = {} + params.each do |key, val| + 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 + new_hash.with_indifferent_access end + else + params end - new_hash.with_indifferent_access end end end -- cgit v1.2.3