Is CGI::Cookie::parse terribly broken?

R

Ryan Mulligan

Is CGI::Cookie::parse 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::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) }
# 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::parse(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]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

CGI::Cookie.parse problem? 0
Mechanize Help 2
cookiejar without cgi 2
CGI::Cookie problem 0
[urllib2] 302 -> can't get cookie 1
Bug in WEBrick::Cookie 0
Performance of CGI::Cookie 4
Downloading and cookie 0

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,835
Latest member
lila30

Latest Threads

Top