ruby-changes:15987
From: wyhaines <ko1@a...>
Date: Fri, 21 May 2010 04:15:05 +0900 (JST)
Subject: [ruby-changes:15987] Ruby:r27932 (ruby_1_8_6): lib/cgi.rb: Backport #229 ; CGI::Cookie objects can get out of sync when CGI::Cookie#value= is used to assign a new value. Also, if a nil value ends up in the array of values for the cookie, CGI::Cookie#to_s would blow up on a gsub error when it tried to CGI::escape the nil value. This is fixed so that nils are treated as empty strings.
wyhaines 2010-05-21 04:14:58 +0900 (Fri, 21 May 2010) New Revision: 27932 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=27932 Log: lib/cgi.rb: Backport #229 [ruby-core:17634]; CGI::Cookie objects can get out of sync when CGI::Cookie#value= is used to assign a new value. Also, if a nil value ends up in the array of values for the cookie, CGI::Cookie#to_s would blow up on a gsub error when it tried to CGI::escape the nil value. This is fixed so that nils are treated as empty strings. Modified files: branches/ruby_1_8_6/lib/cgi.rb Index: ruby_1_8_6/lib/cgi.rb =================================================================== --- ruby_1_8_6/lib/cgi.rb (revision 27931) +++ ruby_1_8_6/lib/cgi.rb (revision 27932) @@ -817,8 +817,8 @@ super(@value) end - attr_accessor("name", "value", "path", "domain", "expires") - attr_reader("secure") + attr_accessor("name", "path", "domain", "expires") + attr_reader("secure", "value") # Set whether the Cookie is a secure cookie or not. # @@ -828,16 +828,17 @@ @secure end + # Set the value of the cookie. + def value=(val) + @value.replace(Array(val)) + end + # Convert the Cookie to its string representation. def to_s buf = "" buf += @name + '=' - if @value.kind_of?(String) - buf += CGI::escape(@value) - else - buf += @value.collect{|v| CGI::escape(v) }.join("&") - end + buf += @value.map { |v| CGI::escape(v.to_s) }.join("&") if @domain buf += '; domain=' + @domain -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/