Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Clean up Safari's ajax POST body

  • Loading branch information...
commit 0f081dde86e02a13870178fd76d5cb27bd1643a3 1 parent a2a2600
@josh josh authored
Showing with 13 additions and 2 deletions.
  1. +7 −2 lib/rack/request.rb
  2. +6 −0 test/spec_rack_request.rb
View
9 lib/rack/request.rb
@@ -119,8 +119,13 @@ def POST
@env["rack.request.form_input"] = @env["rack.input"]
unless @env["rack.request.form_hash"] =
Utils::Multipart.parse_multipart(env)
- @env["rack.request.form_vars"] = @env["rack.input"].read
- @env["rack.request.form_hash"] = Utils.parse_query(@env["rack.request.form_vars"])
+ form_vars = @env["rack.input"].read
+
+ # Fix for Safari Ajax postings that always append \0
+ form_vars.sub!(/\0\z/, '')
+
+ @env["rack.request.form_vars"] = form_vars
+ @env["rack.request.form_hash"] = Utils.parse_query(form_vars)
begin
@env["rack.input"].rewind if @env["rack.input"].respond_to?(:rewind)
View
6 test/spec_rack_request.rb
@@ -103,6 +103,12 @@
req.params.should.equal "foo" => "bar", "quux" => "bla"
end
+ specify "cleans up Safari's ajax POST body" do
+ req = Rack::Request.new \
+ Rack::MockRequest.env_for("/", :input => "foo=bar&quux=bla\0")
+ req.POST.should.equal "foo" => "bar", "quux" => "bla"
+ end
+
specify "can get value by key from params with #[]" do
req = Rack::Request.new \
Rack::MockRequest.env_for("?foo=quux")
Please sign in to comment.
Something went wrong with that request. Please try again.