From 41bbac6ff4d161fc94ef2dc601e06f0a2779dbaf Mon Sep 17 00:00:00 2001 From: Bogdan Gusiev Date: Fri, 2 May 2014 20:57:59 +0300 Subject: [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. --- activesupport/lib/active_support/core_ext/object/to_param.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'activesupport/lib') 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 -- cgit v1.2.3