1
0
Fork 0
mirror of https://github.com/sinatra/sinatra synced 2023-03-27 23:18:01 -04:00

Preserve non-nested params in nested params hash [#117]

This commit is contained in:
Pat Nakajima 2009-01-21 21:55:33 -05:00 committed by Ryan Tomayko
parent 02eec2d57f
commit 40cd096b4f
2 changed files with 17 additions and 0 deletions

View file

@ -376,6 +376,8 @@ module Sinatra
splat = key.scan(/(^[^\[]+)|\[([^\]]+)\]/).flatten.compact
head, last = splat[0..-2], splat[-1]
head.inject(res){ |s,v| s[v] ||= indifferent_hash }[last] = val
else
res[key] = val
end
res
end

View file

@ -176,6 +176,21 @@ describe "Routing" do
assert_equal 'looks good', body
end
it "preserves non-nested params" do
mock_app {
get '/foo' do
assert_equal "2", params["article_id"]
assert_equal "awesome", params['comment']['body']
assert_nil params['comment[body]']
'looks good'
end
}
get '/foo?article_id=2&comment[body]=awesome'
assert ok?
assert_equal 'looks good', body
end
it "supports paths that include spaces" do
mock_app {
get '/path with spaces' do