Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
Miles Egan authored josevalim committed
View
4 actionpack/lib/action_dispatch/http/request.rb
@@ -214,13 +214,13 @@ def session_options=(options)
# Override Rack's GET method to support indifferent access
def GET
- @env["action_dispatch.request.query_parameters"] ||= normalize_parameters(super)
+ @env["action_dispatch.request.query_parameters"] ||= (normalize_parameters(super) || {})
end
alias :query_parameters :GET
# Override Rack's POST method to support indifferent access
def POST
- @env["action_dispatch.request.request_parameters"] ||= normalize_parameters(super)
+ @env["action_dispatch.request.request_parameters"] ||= (normalize_parameters(super) || {})
end
alias :request_parameters :POST
View
12 actionpack/test/dispatch/request_test.rb
@@ -385,6 +385,18 @@ class RequestTest < ActiveSupport::TestCase
assert_equal({"bar" => 2}, request.query_parameters)
end
+ test "parameters still accessible after rack parse error" do
+ mock_rack_env = { "QUERY_STRING" => "x[y]=1&x[y][][w]=2", "rack.input" => "foo" }
+ request = nil
+ begin
+ request = stub_request(mock_rack_env)
+ request.parameters
+ rescue TypeError => e
+ # rack will raise a TypeError when parsing this query string
+ end
+ assert_equal({}, request.parameters)
+ end
+
test "formats with accept header" do
request = stub_request 'HTTP_ACCEPT' => 'text/html'
request.expects(:parameters).at_least_once.returns({})
Please sign in to comment.
Something went wrong with that request. Please try again.