summaryrefslogtreecommitdiff
path: root/lib/cgi/cookie.rb
diff options
context:
space:
mode:
authorxibbar <xibbar@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-04-18 23:47:07 +0000
committerxibbar <xibbar@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-04-18 23:47:07 +0000
commit1f12e40736e195cfa944c1bb33dfcbefa1452579 (patch)
tree5b2c08d449d65a7bc999c988ba3c7e95adc37a0b /lib/cgi/cookie.rb
parent1f2c3b8aa30fc25d69c7242ec2ebc8e3027dd53e (diff)
* lib/cgi/cookie.rb: refactoring.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40363 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/cgi/cookie.rb')
-rw-r--r--lib/cgi/cookie.rb54
1 files changed, 27 insertions, 27 deletions
diff --git a/lib/cgi/cookie.rb b/lib/cgi/cookie.rb
index a26bd16c32f..856526fa925 100644
--- a/lib/cgi/cookie.rb
+++ b/lib/cgi/cookie.rb
@@ -1,6 +1,5 @@
require 'cgi/util'
class CGI
- @@accept_charset="UTF-8" unless defined?(@@accept_charset)
# Class representing an HTTP cookie.
#
# In addition to its specific fields and methods, a Cookie instance
@@ -9,9 +8,9 @@ class CGI
# See RFC 2965.
#
# == Examples of use
- # cookie1 = CGI::Cookie::new("name", "value1", "value2", ...)
- # cookie1 = CGI::Cookie::new("name" => "name", "value" => "value")
- # cookie1 = CGI::Cookie::new('name' => 'name',
+ # cookie1 = CGI::Cookie.new("name", "value1", "value2", ...)
+ # cookie1 = CGI::Cookie.new("name" => "name", "value" => "value")
+ # cookie1 = CGI::Cookie.new('name' => 'name',
# 'value' => ['value1', 'value2', ...],
# 'path' => 'path', # optional
# 'domain' => 'domain', # optional
@@ -35,6 +34,7 @@ class CGI
# cookie1.expires = Time.now + 30
# cookie1.secure = true
class Cookie < Array
+ @@accept_charset="UTF-8" unless defined?(@@accept_charset)
# Create a new CGI::Cookie object.
#
@@ -125,7 +125,7 @@ class CGI
# Convert the Cookie to its string representation.
def to_s
- val = collect{|v| CGI::escape(v) }.join("&")
+ val = collect{|v| CGI.escape(v) }.join("&")
buf = "#{@name}=#{val}"
buf << "; domain=#{@domain}" if @domain
buf << "; path=#{@path}" if @path
@@ -134,32 +134,32 @@ class CGI
buf
end
- end # class Cookie
-
- # Parse a raw cookie string into a hash of cookie-name=>Cookie
- # pairs.
- #
- # cookies = CGI::Cookie::parse("raw_cookie_string")
- # # { "name1" => cookie1, "name2" => cookie2, ... }
- #
- def Cookie::parse(raw_cookie)
- cookies = Hash.new([])
- return cookies unless raw_cookie
+ # Parse a raw cookie string into a hash of cookie-name=>Cookie
+ # pairs.
+ #
+ # cookies = CGI::Cookie.parse("raw_cookie_string")
+ # # { "name1" => cookie1, "name2" => cookie2, ... }
+ #
+ def self.parse(raw_cookie)
+ cookies = Hash.new([])
+ return cookies unless raw_cookie
- raw_cookie.split(/[;,]\s?/).each do |pairs|
- name, values = pairs.split('=',2)
- next unless name and values
- name = CGI::unescape(name)
- values ||= ""
- values = values.split('&').collect{|v| CGI::unescape(v,@@accept_charset) }
- if cookies.has_key?(name)
- values = cookies[name].value + values
+ raw_cookie.split(/[;,]\s?/).each do |pairs|
+ name, values = pairs.split('=',2)
+ next unless name and values
+ name = CGI.unescape(name)
+ values ||= ""
+ values = values.split('&').collect{|v| CGI.unescape(v,@@accept_charset) }
+ if cookies.has_key?(name)
+ values = cookies[name].value + values
+ end
+ cookies[name] = Cookie.new(name, *values)
end
- cookies[name] = Cookie::new(name, *values)
+
+ cookies
end
- cookies
- end
+ end # class Cookie
end