Permalink
Browse files

illegal Cookie PATH handling. closes #13.

When no PATH part given in Set-Cookie header, URL's path part should be
used for path variable. Extracting path part from URL was wrong. fixed.
  • Loading branch information...
1 parent c737a84 commit 0d46b59296c8922ac3554e2818f2578413ea721e @nahi committed Nov 2, 2009
Showing with 22 additions and 2 deletions.
  1. +1 −1 lib/httpclient/cookie.rb
  2. +20 −0 test/test_cookie.rb
  3. +1 −1 test/test_httpclient.rb
@@ -372,7 +372,7 @@ def add(cookie)
# and IE does not check, too.
end
- path ||= url.path.sub(%r|/[^/]*|, '')
+ path ||= url.path.sub(%r|/[^/]*\z|, '')
domain ||= domainname
@cookies.synchronize do
cookie = find_cookie_info(domain, path, name)
View
@@ -343,6 +343,26 @@ def test_add()
assert_equal(nil, c.expires)
end
+ def test_add2()
+ c = WebAgent::Cookie.new()
+ c.name = "hoge"
+ c.value = "funi"
+ c.path = ''
+ c.url = URI.parse("http://www.inac.co.jp/hoge/hoge2/hoge3")
+ @cm.add(c)
+ #
+ c = WebAgent::Cookie.new()
+ c.name = "hoge"
+ c.value = "funi"
+ #c.path = '' NO path given -> same as URL
+ c.url = URI.parse("http://www.inac.co.jp/hoge/hoge2/hoge3")
+ @cm.add(c)
+ #
+ c1, c2 = @cm.cookies
+ assert_equal('', c1.path)
+ assert_equal('/hoge/hoge2', c2.path)
+ end
+
def test_check_cookie_accept_domain()
@cm.accept_domains = [".example1.co.jp", "www1.example.jp"]
@cm.reject_domains = [".example2.co.jp", "www2.example.jp"]
@@ -831,7 +831,7 @@ def test_cookies
@client.get_content('http://rubyforge.org/account/login.php')
@client.save_cookie_store
str = File.read(cookiefile)
- assert_match(%r(http://rubyforge.org/account/login.php foo bar 1924873200 rubyforge.org /login.php 1), str)
+ assert_match(%r(http://rubyforge.org/account/login.php foo bar 1924873200 rubyforge.org /account 1), str)
end
def test_eof_error_length

0 comments on commit 0d46b59

Please sign in to comment.