From cab9face28cb03bc154fdaa6e534989b7573339d Mon Sep 17 00:00:00 2001 From: Toby Date: Sat, 28 Aug 2010 14:36:45 -0500 Subject: [PATCH] Handle blank CONTENT_TYPE in Request#media_type --- lib/rack/request.rb | 3 ++- test/spec_request.rb | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletions(-) diff --git a/lib/rack/request.rb b/lib/rack/request.rb index 23c5e7f..8c60c9f 100644 --- a/lib/rack/request.rb +++ b/lib/rack/request.rb @@ -40,7 +40,8 @@ module Rack # For more information on the use of media types in HTTP, see: # http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7 def media_type - content_type && content_type.split(/\s*[;,]\s*/, 2).first.downcase + return if content_type.nil? || content_type.empty? + content_type.split(/\s*[;,]\s*/, 2).first.downcase end # The media type parameters provided in CONTENT_TYPE as a Hash, or diff --git a/test/spec_request.rb b/test/spec_request.rb index 6daa4fc..ecf9411 100644 --- a/test/spec_request.rb +++ b/test/spec_request.rb @@ -312,6 +312,14 @@ describe Rack::Request do req.media_type_params['bling'].should.equal 'bam' end + should "handle blank CONTENT_TYPE" do + req = Rack::Request.new( + Rack::MockRequest.env_for( "/", 'REQUEST_METHOD' => 'POST', "CONTENT_TYPE" => "" ) + ) + req.media_type.should.be.nil + req.should.be.form_data + end + should "parse multipart form data" do # Adapted from RFC 1867. input = <