Project

General

Profile

Actions

Backport #229

closed

CGI::Cookies can "get out of sync"

Added by NoKarma (Arthur Schreiber) over 15 years ago. Updated almost 13 years ago.


Description

=begin
CGI::Cookies are an instance of a DelegateClass of their @value instance variable,
which is always an Array. But changing a Cookie's value using the #value= instance
method of CGI::Cookie causes the Cookie to "get out of sync":

require "cgi"

cookie = CGI::Cookie.new("my-cookie", "first value", "second value")
cookie.value # => ["first value", "second value"]

cookie[0] # => "first value"
cookie[1] # => "second value"
cookie[2] = "new value"

cookie.each do |val|
val # => "first value", "second value", "new value"
end

cookie.inspect # => "["first value", "second value", "new value"]"
cookie.to_s # => "my-cookie=first+value&second+value&new+value; path="

cookie = CGI::Cookie.new("my-cookie", "first value", "second value")
cookie.value # => ["first value", "second value"]

This makes the cookie get out of sync

cookie.value = [ "test" ]

cookie[0] # => "first value"
cookie[1] # => "second value"
cookie[2] = "new value"

cookie.each do |val|
val # => "first value", "second value", "new value"
end

cookie.inspect # => "["first value", "second value", "new value"]"
cookie.to_s # => "my-cookie=test; path="

The attached patch fixes this issue.
=end


Files

cgi_cookie.patch (1005 Bytes) cgi_cookie.patch NoKarma (Arthur Schreiber), 07/07/2008 07:37 AM

Related issues 1 (0 open1 closed)

Related to Ruby master - Feature #502: CGI::CookieをdelegateからArrayの継承へ変更Closed08/27/2008Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0