diff options
Diffstat (limited to 'test/spec_multipart.rb')
-rw-r--r-- | test/spec_multipart.rb | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/test/spec_multipart.rb b/test/spec_multipart.rb index 9e8a6140..40bab4cd 100644 --- a/test/spec_multipart.rb +++ b/test/spec_multipart.rb @@ -27,7 +27,7 @@ describe Rack::Multipart do it "return nil if content type is not multipart" do env = Rack::MockRequest.env_for("/", "CONTENT_TYPE" => 'application/x-www-form-urlencoded') - Rack::Multipart.parse_multipart(env).must_equal nil + Rack::Multipart.parse_multipart(env).must_be_nil end it "parse multipart content when content type present but filename is not" do @@ -72,6 +72,13 @@ describe Rack::Multipart do end end + it "handles quoted encodings" do + # See #905 + env = Rack::MockRequest.env_for("/", multipart_fixture(:unity3d_wwwform)) + params = Rack::Multipart.parse_multipart(env) + params['user_sid'].encoding.must_equal Encoding::UTF_8 + end + it "raise RangeError if the key space is exhausted" do env = Rack::MockRequest.env_for("/", multipart_fixture(:content_type_and_no_filename)) @@ -88,6 +95,7 @@ describe Rack::Multipart do env['CONTENT_TYPE'] = "multipart/form-data; boundary=----WebKitFormBoundaryWLHCs9qmcJJoyjKR" params = Rack::Multipart.parse_multipart(env) params['profile']['bio'].must_include 'hello' + params['profile'].keys.must_include 'public_email' end it "reject insanely long boundaries" do @@ -99,11 +107,6 @@ describe Rack::Multipart do def rd.rewind; end wr.sync = true - # mock out length to make this pipe look like a Tempfile - def rd.length - 1024 * 1024 * 8 - end - # write to a pipe in a background thread, this will write a lot # unless Rack (properly) shuts down the read end thr = Thread.new do @@ -128,7 +131,7 @@ describe Rack::Multipart do fixture = { "CONTENT_TYPE" => "multipart/form-data; boundary=AaB03x", - "CONTENT_LENGTH" => rd.length.to_s, + "CONTENT_LENGTH" => (1024 * 1024 * 8).to_s, :input => rd, } @@ -297,11 +300,17 @@ describe Rack::Multipart do params["files"][:filename].must_equal "bob's flowers.jpg" end + it "parse multipart form with a null byte in the filename" do + env = Rack::MockRequest.env_for '/', multipart_fixture(:filename_with_null_byte) + params = Rack::Multipart.parse_multipart(env) + params["files"][:filename].must_equal "flowers.exe\u0000.jpg" + end + it "not include file params if no file was selected" do env = Rack::MockRequest.env_for("/", multipart_fixture(:none)) params = Rack::Multipart.parse_multipart(env) params["submit-name"].must_equal "Larry" - params["files"].must_equal nil + params["files"].must_be_nil params.keys.wont_include "files" end @@ -549,7 +558,7 @@ Content-Type: image/jpeg\r it "return nil if no UploadedFiles were used" do data = Rack::Multipart.build_multipart("people" => [{"submit-name" => "Larry", "files" => "contents"}]) - data.must_equal nil + data.must_be_nil end it "raise ArgumentError if params is not a Hash" do |