Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit 40cd096b4f5d6daa0b3ca8cd289367022291175c 1 parent 02eec2d
@nakajima nakajima authored rtomayko committed
Showing with 17 additions and 0 deletions.
  1. +2 −0  lib/sinatra/base.rb
  2. +15 −0 test/routing_test.rb
View
2  lib/sinatra/base.rb
@@ -376,6 +376,8 @@ def nested_params(params)
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
15 test/routing_test.rb
@@ -176,6 +176,21 @@
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
Please sign in to comment.
Something went wrong with that request. Please try again.