提交 3eff7290 编写于 作者: M Miles Egan 提交者: José Valim

make sure request parameters are accessible after rack throws an exception...

make sure request parameters are accessible after rack throws an exception parsing the query string [#3030 state:resolved]
Signed-off-by: NJosé Valim <jose.valim@gmail.com>
上级 933f745d
......@@ -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
......
......@@ -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({})
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册