Skip to content

Commit 5ada603

Browse files
author
wyhaines
committed
lib/cgi.rb: Backport ruby#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
1 parent c11eabf commit 5ada603

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

lib/cgi.rb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -817,8 +817,8 @@ def initialize(name = "", *value)
817817
super(@value)
818818
end
819819

820-
attr_accessor("name", "value", "path", "domain", "expires")
821-
attr_reader("secure")
820+
attr_accessor("name", "path", "domain", "expires")
821+
attr_reader("secure", "value")
822822

823823
# Set whether the Cookie is a secure cookie or not.
824824
#
@@ -828,16 +828,17 @@ def secure=(val)
828828
@secure
829829
end
830830

831+
# Set the value of the cookie.
832+
def value=(val)
833+
@value.replace(Array(val))
834+
end
835+
831836
# Convert the Cookie to its string representation.
832837
def to_s
833838
buf = ""
834839
buf += @name + '='
835840

836-
if @value.kind_of?(String)
837-
buf += CGI::escape(@value)
838-
else
839-
buf += @value.collect{|v| CGI::escape(v) }.join("&")
840-
end
841+
buf += @value.map { |v| CGI::escape(v.to_s) }.join("&")
841842

842843
if @domain
843844
buf += '; domain=' + @domain

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy