Skip to content

Commit

Permalink
removing [nil] from the params
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Jan 24, 2013
1 parent 61eed87 commit ac94515
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 4 additions & 2 deletions actionpack/lib/action_controller/request.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -495,17 +495,19 @@ def normalize_parameters(value)


# Remove nils from the params hash # Remove nils from the params hash
def deep_munge(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| hash.each_value do |v|
case v case v
when Array when Array
v.grep(Hash) { |x| deep_munge(x) } v.grep(Hash) { |x| deep_munge(x) }
v.compact!
when Hash when Hash
deep_munge(v) deep_munge(v)
end end
end end


keys = hash.keys.find_all { |k| hash[k] == [nil] }
keys.each { |k| hash[k] = nil }
hash hash
end end


Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ def teardown
assert_parses({"action"=>{"foo"=>[{"bar"=>nil}]}}, "action[foo][][bar]") assert_parses({"action"=>{"foo"=>[{"bar"=>nil}]}}, "action[foo][][bar]")
end end


def test_array_parses_without_nil
assert_parses({"action" => ['1']}, "action[]=1&action[]")
end

test "query string with empty key" do test "query string with empty key" do
assert_parses( assert_parses(
{ "action" => "create_customer", "full_name" => "David Heinemeier Hansson" }, { "action" => "create_customer", "full_name" => "David Heinemeier Hansson" },
Expand Down

2 comments on commit ac94515

@freakout42
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still not working in 2.3.17

Please sign in to comment.