File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed
Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ module Rack
44 # Rack::MediaType parse media type and parameters out of content_type string
55
66 class MediaType
7- SPLIT_PATTERN = %r{ \s * [;,]\s *}
7+ SPLIT_PATTERN = / [;,]/
88
99 class << self
1010 # The media type (type/subtype) portion of the CONTENT_TYPE header
@@ -15,7 +15,11 @@ class << self
1515 # http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7
1616 def type ( content_type )
1717 return nil unless content_type
18- content_type . split ( SPLIT_PATTERN , 2 ) . first . tap &:downcase!
18+ if type = content_type . split ( SPLIT_PATTERN , 2 ) . first
19+ type . rstrip!
20+ type . downcase!
21+ type
22+ end
1923 end
2024
2125 # The media type parameters provided in CONTENT_TYPE as a Hash, or
@@ -27,9 +31,10 @@ def params(content_type)
2731 return { } if content_type . nil?
2832
2933 content_type . split ( SPLIT_PATTERN ) [ 1 ..-1 ] . each_with_object ( { } ) do |s , hsh |
34+ s . strip!
3035 k , v = s . split ( '=' , 2 )
31-
32- hsh [ k . tap ( & :downcase! ) ] = strip_doublequotes ( v )
36+ k . downcase!
37+ hsh [ k ] = strip_doublequotes ( v )
3338 end
3439 end
3540
You can’t perform that action at this time.
0 commit comments