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
|
end
|
||||||
|
|
||||||
# Enable string or symbol key access to the nested params hash.
|
# Enable string or symbol key access to the nested params hash.
|
||||||
def indifferent_params(params)
|
def indifferent_params(object)
|
||||||
params = indifferent_hash.merge(params)
|
case object
|
||||||
params.each do |key, value|
|
when Hash
|
||||||
case value
|
new_hash = indifferent_hash
|
||||||
when Hash then params[key] = indifferent_params(value)
|
object.each { |key, value| new_hash[key] = indifferent_params(value) }
|
||||||
when Array then params[key] = value.map { |item| indifferent_params(item) }
|
new_hash
|
||||||
end
|
when Array
|
||||||
|
object.map { |item| indifferent_params(item) }
|
||||||
|
else
|
||||||
|
object
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -372,6 +372,18 @@ class RoutingTest < Test::Unit::TestCase
|
||||||
assert_equal 'well, alright', body
|
assert_equal 'well, alright', body
|
||||||
end
|
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
|
it "supports deeply nested params" do
|
||||||
expected_params = {
|
expected_params = {
|
||||||
"emacs" => {
|
"emacs" => {
|
||||||
|
|
Loading…
Reference in New Issue