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 @@ -215,8 +215,12 @@ def parse_cookies_header(header)
215
215
# the Cookie header such that those with more specific Path attributes
216
216
# precede those with less specific. Ordering with respect to other
217
217
# attributes (e.g., Domain) is unspecified.
218
- cookies = parse_query ( header , ';,' ) { |s | unescape ( s ) rescue s }
219
- cookies . each_with_object ( { } ) { |( k , v ) , hash | hash [ k ] = Array === v ? v . first : v }
218
+ return { } unless header
219
+ header . split ( /[;,] */n ) . each_with_object ( { } ) do |cookie , cookies |
220
+ next if cookie . empty?
221
+ key , value = cookie . split ( '=' , 2 )
222
+ cookies [ key ] = ( unescape ( value ) rescue value ) unless cookies . key? ( key )
223
+ end
220
224
end
221
225
module_function :parse_cookies_header
222
226
Original file line number Diff line number Diff line change @@ -512,6 +512,10 @@ def initialize(*)
512
512
513
513
env = Rack ::MockRequest . env_for ( "" , "HTTP_COOKIE" => "foo=bar" ) . freeze
514
514
Rack ::Utils . parse_cookies ( env ) . must_equal ( { "foo" => "bar" } )
515
+
516
+ env = Rack ::MockRequest . env_for ( "" , "HTTP_COOKIE" => "%66oo=baz;foo=bar" )
517
+ cookies = Rack ::Utils . parse_cookies ( env )
518
+ cookies . must_equal ( { "%66oo" => "baz" , "foo" => "bar" } )
515
519
end
516
520
517
521
it "adds new cookies to nil header" do
You can’t perform that action at this time.
0 commit comments