diff options
author | Rafael Mendonça França <rafael.franca@plataformatec.com.br> | 2014-07-18 17:56:51 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafael.franca@plataformatec.com.br> | 2014-07-18 18:10:30 -0300 |
commit | 28ba782f06d97085862f72227815d492fcfc83c9 (patch) | |
tree | 3abe334d2b4629dd6fd0a4742695b59b7d775d0e | |
parent | 2683d278913529400d13fd32b2a85e9eaa7f272c (diff) | |
download | rack-28ba782f06d97085862f72227815d492fcfc83c9.tar.gz |
Fix media_type_params when Content-Type parameters contains quoted-strings
According RFC 2616, the Content-Type parameters value can be even a token or a quoted-string: media-type = type "/" subtype *( ";" parameter ) type = token subtype = token parameter = attribute "=" value attribute = token value = token | quoted-string quoted-string = ( <"> *(qdtext | quoted-pair ) <"> ) qdtext = <any TEXT except <">>" quoted-pair = "\" CHAR
-rw-r--r-- | lib/rack/request.rb | 2 | ||||
-rw-r--r-- | test/spec_request.rb | 4 |
2 files changed, 4 insertions, 2 deletions
diff --git a/lib/rack/request.rb b/lib/rack/request.rb index 5a446acd..ac94026c 100644 --- a/lib/rack/request.rb +++ b/lib/rack/request.rb @@ -52,7 +52,7 @@ module Rack return {} if content_type.nil? Hash[*content_type.split(/\s*[;,]\s*/)[1..-1]. collect { |s| s.split('=', 2) }. - map { |k,v| [k.downcase, v] }.flatten] + map { |k,v| [k.downcase, v.gsub(/\A"|"\z/, "")] }.flatten] end # The character set of the request body if a "charset" media type diff --git a/test/spec_request.rb b/test/spec_request.rb index e5ec254e..09a308a6 100644 --- a/test/spec_request.rb +++ b/test/spec_request.rb @@ -611,7 +611,7 @@ describe Rack::Request do should "handle multiple media type parameters" do req = Rack::Request.new \ Rack::MockRequest.env_for("/", - "CONTENT_TYPE" => 'text/plain; foo=BAR,baz=bizzle dizzle;BLING=bam') + "CONTENT_TYPE" => 'text/plain; foo=BAR,baz=bizzle dizzle;BLING=bam;blong="boo";zump="zoo\"o"') req.should.not.be.form_data req.media_type_params.should.include 'foo' req.media_type_params['foo'].should.equal 'BAR' @@ -620,6 +620,8 @@ describe Rack::Request do req.media_type_params.should.not.include 'BLING' req.media_type_params.should.include 'bling' req.media_type_params['bling'].should.equal 'bam' + req.media_type_params['blong'].should.equal 'boo' + req.media_type_params['zump'].should.equal 'zoo\"o' end should "parse with junk before boundry" do |