Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle failure to upcase invalid UTF8 strings for _method values #1249

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/rack/methodoverride.rb
Expand Up @@ -26,7 +26,11 @@ def method_override(env)
req = Request.new(env)
method = method_override_param(req) ||
env[HTTP_METHOD_OVERRIDE_HEADER]
method.to_s.upcase
begin
method.to_s.upcase
rescue ArgumentError
env["rack.errors"].puts "Invalid string for method"
end
end

private
Expand Down
18 changes: 17 additions & 1 deletion test/spec_methodoverride.rb
Expand Up @@ -8,7 +8,7 @@ def app
[200, {"Content-Type" => "text/plain"}, []]
}))
end

should "not affect GET requests" do
env = Rack::MockRequest.env_for("/?_method=delete", :method => "GET")
app.call env
Expand All @@ -23,6 +23,22 @@ def app
env["REQUEST_METHOD"].should.equal "PUT"
end

if RUBY_VERSION >= "1.9"
should "set rack.errors for invalid UTF8 _method values" do
errors = StringIO.new
env = Rack::MockRequest.env_for("/",
:method => "POST",
:input => "_method=\xBF".force_encoding("ASCII-8BIT"),
"rack.errors" => errors)

app.call env

errors.rewind
errors.read.should.equal "Invalid string for method\n"
env["REQUEST_METHOD"].should.equal "POST"
end
end

should "modify REQUEST_METHOD for POST requests when X-HTTP-Method-Override is set" do
env = Rack::MockRequest.env_for("/",
:method => "POST",
Expand Down