Skip to content
This repository
Browse code

make sure request parameters are accessible after rack throws an exce…

…ption parsing the query string [#3030 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
commit 3eff729079a1a9e717e7872bdae19c8703b280ac 1 parent 933f745
authored July 18, 2010 josevalim committed October 12, 2010
4  actionpack/lib/action_dispatch/http/request.rb
@@ -214,13 +214,13 @@ def session_options=(options)
214 214
 
215 215
     # Override Rack's GET method to support indifferent access
216 216
     def GET
217  
-      @env["action_dispatch.request.query_parameters"] ||= normalize_parameters(super)
  217
+      @env["action_dispatch.request.query_parameters"] ||= (normalize_parameters(super) || {})
218 218
     end
219 219
     alias :query_parameters :GET
220 220
 
221 221
     # Override Rack's POST method to support indifferent access
222 222
     def POST
223  
-      @env["action_dispatch.request.request_parameters"] ||= normalize_parameters(super)
  223
+      @env["action_dispatch.request.request_parameters"] ||= (normalize_parameters(super) || {})
224 224
     end
225 225
     alias :request_parameters :POST
226 226
 
12  actionpack/test/dispatch/request_test.rb
@@ -385,6 +385,18 @@ class RequestTest < ActiveSupport::TestCase
385 385
     assert_equal({"bar" => 2}, request.query_parameters)
386 386
   end
387 387
 
  388
+  test "parameters still accessible after rack parse error" do
  389
+    mock_rack_env = { "QUERY_STRING" => "x[y]=1&x[y][][w]=2", "rack.input" => "foo" }
  390
+    request = nil
  391
+    begin
  392
+      request = stub_request(mock_rack_env) 
  393
+      request.parameters
  394
+    rescue TypeError => e
  395
+      # rack will raise a TypeError when parsing this query string
  396
+    end
  397
+    assert_equal({}, request.parameters)
  398
+  end
  399
+
388 400
   test "formats with accept header" do
389 401
     request = stub_request 'HTTP_ACCEPT' => 'text/html'
390 402
     request.expects(:parameters).at_least_once.returns({})

0 notes on commit 3eff729

Please sign in to comment.
Something went wrong with that request. Please try again.