R
Ryan Mulligan
Is CGI::Cookie:arse meant to be used on the contents of the Set-Cookie
header or the Cookie header, or both?
Here is what happens when I use it on the Set-Cookie header:
require 'cgi'
# File lib/cgi.rb, line 875
# def Cookie:arse(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) }
# if cookies.has_key?(name)
# values = cookies[name].value + values
# end
# cookies[name] = Cookie::new(name, *values)
# end
# cookies
# end
asetcookie = "phpbb3_q3k1i_u=1; expires=Thu, 23-Jul-2009 17:27:04 GMT;
path=/; domain=.brawlsnapshots.com; HttpOnly, phpbb3_q3k1i_k=;
expires=Thu, 23-Jul-2009 17:27:04 GMT; path=/;
domain=.brawlsnapshots.com; HttpOnly,
phpbb3_q3k1i_sid=3c2ab8dae46098004b66dcd2ff6c3180; expires=Thu,
23-Jul-2009 17:27:04 GMT; path=/; domain=.brawlsnapshots.com; HttpOnly,
phpbb3_q3k1i_u=1000; expires=Thu, 23-Jul-2009 17:27:04 GMT; path=/;
domain=.brawlsnapshots.com; HttpOnly, phpbb3_q3k1i_k=c06c23e2a199173a;
expires=Thu, 23-Jul-2009 17:27:04 GMT; path=/;
domain=.brawlsnapshots.com; HttpOnly,
phpbb3_q3k1i_sid=85d32e487ffd5bc8fad948e327866597; expires=Thu,
23-Jul-2009 17:27:04 GMT; path=/; domain=.brawlsnapshots.com; HttpOnly"
puts "The Cookies:"
puts asetcookie
puts "Ruby says:"
puts CGI::Cookie:arse(asetcookie).inspect
OUTPUT:
ryan@rtmlap:~/rb/code/test$ ruby ~/test.rb
The Cookies:
phpbb3_q3k1i_u=1; expires=Thu, 23-Jul-2009 17:27:04 GMT; path=/;
domain=.brawlsnapshots.com; HttpOnly, phpbb3_q3k1i_k=; expires=Thu,
23-Jul-2009 17:27:04 GMT; path=/; domain=.brawlsnapshots.com; HttpOnly,
phpbb3_q3k1i_sid=3c2ab8dae46098004b66dcd2ff6c3180; expires=Thu,
23-Jul-2009 17:27:04 GMT; path=/; domain=.brawlsnapshots.com; HttpOnly,
phpbb3_q3k1i_u=1000; expires=Thu, 23-Jul-2009 17:27:04 GMT; path=/;
domain=.brawlsnapshots.com; HttpOnly, phpbb3_q3k1i_k=c06c23e2a199173a;
expires=Thu, 23-Jul-2009 17:27:04 GMT; path=/;
domain=.brawlsnapshots.com; HttpOnly,
phpbb3_q3k1i_sid=85d32e487ffd5bc8fad948e327866597; expires=Thu,
23-Jul-2009 17:27:04 GMT; path=/; domain=.brawlsnapshots.com; HttpOnly
Ruby says:
{"phpbb3_q3k1i_sid"=>["3c2ab8dae46098004b66dcd2ff6c3180",
"85d32e487ffd5bc8fad948e327866597"], "expires"=>["Thu", "Thu", "Thu",
"Thu", "Thu", "Thu"], "domain"=>[".brawlsnapshots.com",
".brawlsnapshots.com", ".brawlsnapshots.com", ".brawlsnapshots.com",
".brawlsnapshots.com", ".brawlsnapshots.com"], "phpbb3_q3k1i_u"
VERSION:
ruby 1.8.6 (2007-09-24 patchlevel 111) [i486-linux]
header or the Cookie header, or both?
Here is what happens when I use it on the Set-Cookie header:
require 'cgi'
# File lib/cgi.rb, line 875
# def Cookie:arse(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) }
# if cookies.has_key?(name)
# values = cookies[name].value + values
# end
# cookies[name] = Cookie::new(name, *values)
# end
# cookies
# end
asetcookie = "phpbb3_q3k1i_u=1; expires=Thu, 23-Jul-2009 17:27:04 GMT;
path=/; domain=.brawlsnapshots.com; HttpOnly, phpbb3_q3k1i_k=;
expires=Thu, 23-Jul-2009 17:27:04 GMT; path=/;
domain=.brawlsnapshots.com; HttpOnly,
phpbb3_q3k1i_sid=3c2ab8dae46098004b66dcd2ff6c3180; expires=Thu,
23-Jul-2009 17:27:04 GMT; path=/; domain=.brawlsnapshots.com; HttpOnly,
phpbb3_q3k1i_u=1000; expires=Thu, 23-Jul-2009 17:27:04 GMT; path=/;
domain=.brawlsnapshots.com; HttpOnly, phpbb3_q3k1i_k=c06c23e2a199173a;
expires=Thu, 23-Jul-2009 17:27:04 GMT; path=/;
domain=.brawlsnapshots.com; HttpOnly,
phpbb3_q3k1i_sid=85d32e487ffd5bc8fad948e327866597; expires=Thu,
23-Jul-2009 17:27:04 GMT; path=/; domain=.brawlsnapshots.com; HttpOnly"
puts "The Cookies:"
puts asetcookie
puts "Ruby says:"
puts CGI::Cookie:arse(asetcookie).inspect
OUTPUT:
ryan@rtmlap:~/rb/code/test$ ruby ~/test.rb
The Cookies:
phpbb3_q3k1i_u=1; expires=Thu, 23-Jul-2009 17:27:04 GMT; path=/;
domain=.brawlsnapshots.com; HttpOnly, phpbb3_q3k1i_k=; expires=Thu,
23-Jul-2009 17:27:04 GMT; path=/; domain=.brawlsnapshots.com; HttpOnly,
phpbb3_q3k1i_sid=3c2ab8dae46098004b66dcd2ff6c3180; expires=Thu,
23-Jul-2009 17:27:04 GMT; path=/; domain=.brawlsnapshots.com; HttpOnly,
phpbb3_q3k1i_u=1000; expires=Thu, 23-Jul-2009 17:27:04 GMT; path=/;
domain=.brawlsnapshots.com; HttpOnly, phpbb3_q3k1i_k=c06c23e2a199173a;
expires=Thu, 23-Jul-2009 17:27:04 GMT; path=/;
domain=.brawlsnapshots.com; HttpOnly,
phpbb3_q3k1i_sid=85d32e487ffd5bc8fad948e327866597; expires=Thu,
23-Jul-2009 17:27:04 GMT; path=/; domain=.brawlsnapshots.com; HttpOnly
Ruby says:
{"phpbb3_q3k1i_sid"=>["3c2ab8dae46098004b66dcd2ff6c3180",
"85d32e487ffd5bc8fad948e327866597"], "expires"=>["Thu", "Thu", "Thu",
"Thu", "Thu", "Thu"], "domain"=>[".brawlsnapshots.com",
".brawlsnapshots.com", ".brawlsnapshots.com", ".brawlsnapshots.com",
".brawlsnapshots.com", ".brawlsnapshots.com"], "phpbb3_q3k1i_u"
VERSION:
ruby 1.8.6 (2007-09-24 patchlevel 111) [i486-linux]