Is CGI::Cookie::parse terribly broken?

Discussion in 'Ruby' started by Ryan Mulligan, Jul 23, 2008.

  1. 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]
    --
    Posted via http://www.ruby-forum.com/.
    Ryan Mulligan, Jul 23, 2008
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JDS
    Replies:
    2
    Views:
    438
  2. Angus Parvis

    XLS problem? JBoss terribly slow

    Angus Parvis, Aug 31, 2004, in forum: XML
    Replies:
    2
    Views:
    623
    Angus Parvis
    Aug 31, 2004
  3. Replies:
    8
    Views:
    782
    Juan T. Llibre
    May 13, 2008
  4. Bill Kelly

    CGI::Cookie.parse problem?

    Bill Kelly, Jan 25, 2006, in forum: Ruby
    Replies:
    0
    Views:
    129
    Bill Kelly
    Jan 25, 2006
  5. Xeno Campanoli
    Replies:
    2
    Views:
    139
    Xeno Campanoli
    Jul 10, 2008
Loading...

Share This Page