Permalink
Browse files

removing [nil] from the params

  • Loading branch information...
tenderlove committed Jan 24, 2013
1 parent 61eed87 commit ac9451523130c5561e2598c828ab407fc1137668
@@ -495,17 +495,19 @@ def normalize_parameters(value)
# Remove nils from the params hash
def deep_munge(hash)
+ keys = hash.keys.find_all { |k| hash[k] == [nil] }
+ keys.each { |k| hash[k] = nil }
+
hash.each_value do |v|
case v
when Array
v.grep(Hash) { |x| deep_munge(x) }
+ v.compact!
when Hash
deep_munge(v)
end
end
- keys = hash.keys.find_all { |k| hash[k] == [nil] }
- keys.each { |k| hash[k] = nil }
hash
end
@@ -89,6 +89,10 @@ def teardown
assert_parses({"action"=>{"foo"=>[{"bar"=>nil}]}}, "action[foo][][bar]")
end
+ def test_array_parses_without_nil
+ assert_parses({"action" => ['1']}, "action[]=1&action[]")
+ end
+
test "query string with empty key" do
assert_parses(
{ "action" => "create_customer", "full_name" => "David Heinemeier Hansson" },

2 comments on commit ac94515

@freakout42

This comment has been minimized.

Show comment Hide comment
@freakout42

freakout42 Feb 1, 2013

For me the patch doesn't work:

i have:

def ping
raise params.inspect
end

i do:

curl -L -v -X POST "http://toarx.wpack.de/home/ping" -H "Content-Type: application/json" -d '{"xxx":[], "yyy":[null]}'

i get (for 3.2.11):

RuntimeError ({"xxx"=>nil, "yyy"=>nil, "controller"=>"home", "action"=>"ping", "home"=>{"xxx"=>nil, "yyy"=>nil}}):
  app/controllers/home_controller.rb:3:in `ping'

i get (for 2.3.16):

Processing HostsController#ping (for 188.138.34.38 at 2013-01-30 13:36:52) [POST]
  Parameters: {"xxx"=>[], "yyy"=>[nil], "controller"=>"hosts", "action"=>"ping"}
                                 !!!!!

For me the patch doesn't work:

i have:

def ping
raise params.inspect
end

i do:

curl -L -v -X POST "http://toarx.wpack.de/home/ping" -H "Content-Type: application/json" -d '{"xxx":[], "yyy":[null]}'

i get (for 3.2.11):

RuntimeError ({"xxx"=>nil, "yyy"=>nil, "controller"=>"home", "action"=>"ping", "home"=>{"xxx"=>nil, "yyy"=>nil}}):
  app/controllers/home_controller.rb:3:in `ping'

i get (for 2.3.16):

Processing HostsController#ping (for 188.138.34.38 at 2013-01-30 13:36:52) [POST]
  Parameters: {"xxx"=>[], "yyy"=>[nil], "controller"=>"hosts", "action"=>"ping"}
                                 !!!!!
@freakout42

This comment has been minimized.

Show comment Hide comment
@freakout42

freakout42 Feb 12, 2013

Still not working in 2.3.17

Still not working in 2.3.17

Please sign in to comment.