mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_6@27932 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
c11eabf5c4
commit
5ada603a7e
1 changed files with 8 additions and 7 deletions
15
lib/cgi.rb
15
lib/cgi.rb
|
@ -817,8 +817,8 @@ class CGI
|
|||
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 @@ class CGI
|
|||
@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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue