Params processing shouldn't error on arrays of objects other than hashes.
This commit is contained in:
parent
3f480092f1
commit
0d6c14c45e
|
@ -868,13 +868,16 @@ module Sinatra
|
|||
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
|
||||
|
||||
|
|
|
@ -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" => {
|
||||
|
|
Loading…
Reference in New Issue