Project

General

Profile

This project is closed and read-only.

Actions

Backport #229

closed

CGI::Cookies can "get out of sync"

Backport #229: CGI::Cookies can "get out of sync"

Added by NoKarma (Arthur Schreiber) about 18 years ago. Updated over 15 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 - Feature #502: CGI::CookieをdelegateからArrayの継承へ変更ClosedActions

Updated by shyouhei (Shyouhei Urabe) over 17 years ago Actions #1

  • Assignee set to xibbar (Takeyuki FUJIOKA)

=begin

=end

Updated by marcandre (Marc-Andre Lafortune) about 17 years ago Actions #2

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

=begin
Applied in changeset r24913.
=end

Updated by marcandre (Marc-Andre Lafortune) about 17 years ago Actions #3

=begin
Notes: the problem was even more acute in Ruby 1.9, since Cookie is no longer a Delegate (ref: issue #502), e.g. cookie.value.unshift("something"). Rubyspecs have been updated for this kind of check.

Patch was applied as is in Ruby 1.8 and modified for Ruby 1.9 to account for the fact that Cookie is an Array.
=end

Updated by shyouhei (Shyouhei Urabe) almost 17 years ago Actions #4

  • Status changed from Closed to Assigned
  • Assignee changed from xibbar (Takeyuki FUJIOKA) to wyhaines (Kirk Haines)

=begin
1.8.6 also has this issue.
=end

Updated by wyhaines (Kirk Haines) over 16 years ago Actions #5

  • Status changed from Assigned to Closed

=begin
This issue was solved with changeset r27932.
Arthur, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.

=end

Actions

Also available in: PDF Atom