ruby-changes:19189
From: nahi <ko1@a...>
Date: Fri, 1 Apr 2011 19:02:14 +0900 (JST)
Subject: [ruby-changes:19189] Ruby:r31228 (trunk): Fri Apr 1 18:53:06 2011 NAKAMURA, Hiroshi <nahi@r...>
nahi 2011-04-01 19:02:03 +0900 (Fri, 01 Apr 2011) New Revision: 31228 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=31228 Log: Fri Apr 1 18:53:06 2011 NAKAMURA, Hiroshi <nahi@r...> * lib/webrick/cookie.rb (WEBrick::Cookie.parse): 'white space is permitted between tokens' according to RFC2965. Though 'Netscape spec' does not define the syntax clearly, make it tolerant as a server. As a real-world example, rest-client gem sends 'Cookie: foo=1;bar=2' * test/webrick/test_cookie.rb (test_parse_non_whitespace): test it. Modified files: trunk/ChangeLog trunk/lib/webrick/cookie.rb trunk/test/webrick/test_cookie.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 31227) +++ ChangeLog (revision 31228) @@ -1,3 +1,13 @@ +Fri Apr 1 18:53:06 2011 NAKAMURA, Hiroshi <nahi@r...> + + * lib/webrick/cookie.rb (WEBrick::Cookie.parse): 'white space is + permitted between tokens' according to RFC2965. Though 'Netscape + spec' does not define the syntax clearly, make it tolerant as a + server. As a real-world example, rest-client gem sends + 'Cookie: foo=1;bar=2' + + * test/webrick/test_cookie.rb (test_parse_non_whitespace): test it. + Fri Apr 1 13:19:20 2011 Nobuyoshi Nakada <nobu@r...> * vm_core.h (RUBY_VM_CHECK_INTS_TH): merge a patch by ko1 Index: lib/webrick/cookie.rb =================================================================== --- lib/webrick/cookie.rb (revision 31227) +++ lib/webrick/cookie.rb (revision 31228) @@ -57,7 +57,7 @@ ret = [] cookie = nil ver = 0 - str.split(/[;,]\s+/).each{|x| + str.split(/[;,]\s*/).each{|x| key, val = x.split(/=/,2) val = val ? HTTPUtils::dequote(val) : "" case key Index: test/webrick/test_cookie.rb =================================================================== --- test/webrick/test_cookie.rb (revision 31227) +++ test/webrick/test_cookie.rb (revision 31228) @@ -54,6 +54,26 @@ assert_equal("9865ecfd514be7f7", cookies[1].value) end + def test_parse_non_whitespace + data = [ + '$Version="1";', + 'Customer="WILE_E_COYOTE";$Path="/acme";', + 'Part_Number="Rocket_Launcher_0001";$Path="/acme";', + 'Shipping="FedEx";$Path="/acme"' + ].join + cookies = WEBrick::Cookie.parse(data) + assert_equal(1, cookies[0].version) + assert_equal("Customer", cookies[0].name) + assert_equal("WILE_E_COYOTE", cookies[0].value) + assert_equal("/acme", cookies[0].path) + assert_equal(1, cookies[1].version) + assert_equal("Part_Number", cookies[1].name) + assert_equal("Rocket_Launcher_0001", cookies[1].value) + assert_equal(1, cookies[2].version) + assert_equal("Shipping", cookies[2].name) + assert_equal("FedEx", cookies[2].value) + end + def test_parse_set_cookie data = %(Customer="WILE_E_COYOTE"; Version="1"; Path="/acme") cookie = WEBrick::Cookie.parse_set_cookie(data) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/