diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb index 9cf465ca..e299267c 100644 --- a/lib/sinatra/base.rb +++ b/lib/sinatra/base.rb @@ -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 diff --git a/test/routing_test.rb b/test/routing_test.rb index 6ee5eeae..21753153 100644 --- a/test/routing_test.rb +++ b/test/routing_test.rb @@ -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