From cc8bc6b7b6cb429c6a0a4bebc180b70b564e4e99 Mon Sep 17 00:00:00 2001 From: nahi Date: Fri, 1 Apr 2011 10:02:03 +0000 Subject: [PATCH] Fri Apr 1 18:53:06 2011 NAKAMURA, Hiroshi * 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31228 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 10 ++++++++++ lib/webrick/cookie.rb | 2 +- test/webrick/test_cookie.rb | 20 ++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index b30d43d93e..87a4e97fb4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +Fri Apr 1 18:53:06 2011 NAKAMURA, Hiroshi + + * 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 * vm_core.h (RUBY_VM_CHECK_INTS_TH): merge a patch by ko1 diff --git a/lib/webrick/cookie.rb b/lib/webrick/cookie.rb index 814e6645a3..eb3b63b006 100644 --- a/lib/webrick/cookie.rb +++ b/lib/webrick/cookie.rb @@ -57,7 +57,7 @@ module WEBrick 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 diff --git a/test/webrick/test_cookie.rb b/test/webrick/test_cookie.rb index 14771fd01c..1275dc8eff 100644 --- a/test/webrick/test_cookie.rb +++ b/test/webrick/test_cookie.rb @@ -54,6 +54,26 @@ class TestWEBrickCookie < Test::Unit::TestCase 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)