Permalink
Browse files

Params processing shouldn't error on arrays of objects other than has…

…hes.
  • Loading branch information...
1 parent 3f48009 commit 0d6c14c45ee0fc86c256b5c9ace35b36e06c360d @chanks chanks committed Feb 1, 2012
Showing with 22 additions and 7 deletions.
  1. +10 −7 lib/sinatra/base.rb
  2. +12 −0 test/routing_test.rb
View
@@ -868,13 +868,16 @@ def static!
end
# Enable string or symbol key access to the nested params hash.
- def indifferent_params(params)
- params = indifferent_hash.merge(params)
- params.each do |key, value|
- case value
- when Hash then params[key] = indifferent_params(value)
- when Array then params[key] = value.map { |item| indifferent_params(item) }
- end
+ def indifferent_params(object)
+ case object
+ when Hash
+ new_hash = indifferent_hash
+ object.each { |key, value| new_hash[key] = indifferent_params(value) }
+ new_hash
+ when Array
+ object.map { |item| indifferent_params(item) }
+ else
+ object
end
end
View
@@ -372,6 +372,18 @@ class RoutingTest < Test::Unit::TestCase
assert_equal 'well, alright', body
end
+ it "supports arrays within params" do
+ mock_app {
+ get '/foo' do
+ assert_equal ['A', 'B'], params['bar']
+ 'looks good'
+ end
+ }
+ get '/foo?bar[]=A&bar[]=B'
+ assert ok?
+ assert_equal 'looks good', body
+ end
+
it "supports deeply nested params" do
expected_params = {
"emacs" => {

0 comments on commit 0d6c14c

Please sign in to comment.