File tree Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -212,8 +212,12 @@ def parse_cookies_header(header)
212
212
# The syntax for cookie headers only supports semicolons
213
213
# User Agent -> Server ==
214
214
# Cookie: SID=31d4d96e407aad42; lang=en-US
215
- cookies = parse_query ( header , ';' ) { |s | unescape ( s ) rescue s }
216
- cookies . each_with_object ( { } ) { |( k , v ) , hash | hash [ k ] = Array === v ? v . first : v }
215
+ return { } unless header
216
+ header . split ( /[;] */n ) . each_with_object ( { } ) do |cookie , cookies |
217
+ next if cookie . empty?
218
+ key , value = cookie . split ( '=' , 2 )
219
+ cookies [ key ] = ( unescape ( value ) rescue value ) unless cookies . key? ( key )
220
+ end
217
221
end
218
222
219
223
def add_cookie_to_header ( header , key , value )
Original file line number Diff line number Diff line change @@ -524,6 +524,10 @@ def initialize(*)
524
524
525
525
env = Rack ::MockRequest . env_for ( "" , "HTTP_COOKIE" => "foo=bar" ) . freeze
526
526
Rack ::Utils . parse_cookies ( env ) . must_equal ( { "foo" => "bar" } )
527
+
528
+ env = Rack ::MockRequest . env_for ( "" , "HTTP_COOKIE" => "%66oo=baz;foo=bar" )
529
+ cookies = Rack ::Utils . parse_cookies ( env )
530
+ cookies . must_equal ( { "%66oo" => "baz" , "foo" => "bar" } )
527
531
end
528
532
529
533
it "adds new cookies to nil header" do
You can’t perform that action at this time.
0 commit comments