aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorBogdan Gusiev <agresso@gmail.com>2014-05-02 20:57:59 +0300
committerBogdan Gusiev <agresso@gmail.com>2014-05-03 07:40:50 +0300
commit41bbac6ff4d161fc94ef2dc601e06f0a2779dbaf (patch)
treef96e9f1a9eceb039803c19ffde33eb5712e19c93 /activesupport/lib
parent4565cb7ccbd5f29a194c197c5ece9fb81f889d32 (diff)
downloadrails-41bbac6ff4d161fc94ef2dc601e06f0a2779dbaf.tar.gz
rails-41bbac6ff4d161fc94ef2dc601e06f0a2779dbaf.tar.bz2
rails-41bbac6ff4d161fc94ef2dc601e06f0a2779dbaf.zip
[Fixes #14948] Hash#to_query: Changed a way how empty hash and empty array are serialized
Empty Hash or Array should not present in serialization result {a: []}.to_query # => "" {a: {}}.to_query # => "" For more info see #14948.
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/core_ext/object/to_param.rb12
1 files changed, 6 insertions, 6 deletions
diff --git a/activesupport/lib/active_support/core_ext/object/to_param.rb b/activesupport/lib/active_support/core_ext/object/to_param.rb
index 13be0038c2..0611eb819d 100644
--- a/activesupport/lib/active_support/core_ext/object/to_param.rb
+++ b/activesupport/lib/active_support/core_ext/object/to_param.rb
@@ -51,12 +51,12 @@ class Hash
#
# This method is also aliased as +to_query+.
def to_param(namespace = nil)
- if empty?
- namespace ? nil.to_query(namespace) : ''
- else
- collect do |key, value|
+ collect do |key, value|
+ unless (value.is_a?(Hash) || value.is_a?(Array)) && value.empty?
value.to_query(namespace ? "#{namespace}[#{key}]" : key)
- end.sort! * '&'
- end
+ else
+ nil
+ end
+ end.compact.sort! * '&'
end
end