Skip to content

Commit

Permalink
make sure request parameters are accessible after rack throws an exce…
Browse files Browse the repository at this point in the history
…ption parsing the query string [#3030 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information
Miles Egan authored and josevalim committed Oct 11, 2010
1 parent 933f745 commit 3eff729
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions actionpack/lib/action_dispatch/http/request.rb
Expand Up @@ -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

Expand Down
12 changes: 12 additions & 0 deletions actionpack/test/dispatch/request_test.rb
Expand Up @@ -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({})
Expand Down

0 comments on commit 3eff729

Please sign in to comment.