aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorSantiago Pastorino <santiago@wyeworks.com>2013-08-19 15:17:11 -0300
committerSantiago Pastorino <santiago@wyeworks.com>2013-08-19 15:17:27 -0300
commite5945e49653e38f4df445284eafda6fa288f071b (patch)
treef40ccbc886b65f1ba6f513a1691e35790d0ddcc8 /actionpack/lib
parentce2d837a5a27bfa9306a149233a451840790a104 (diff)
downloadrails-e5945e49653e38f4df445284eafda6fa288f071b.tar.gz
rails-e5945e49653e38f4df445284eafda6fa288f071b.tar.bz2
rails-e5945e49653e38f4df445284eafda6fa288f071b.zip
Organize normalize_encoding_params' conditionals a bit better and use a case statement for it
Refactor of the work done in #11891
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_dispatch/http/parameters.rb33
1 files changed, 18 insertions, 15 deletions
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