Skip to content

Commit

Permalink
handling bad cookies
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Mar 3, 2009
1 parent 245ab10 commit 727fa04
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions History.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
= Mechanize CHANGELOG

=== HEAD

* Bug Fixes:
* Fixed a bug with bad cookie parsing

=== 0.9.1 2009/02/23

* New Features:
Expand Down
2 changes: 2 additions & 0 deletions lib/www/mechanize/cookie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ def self.parse(uri, str, log = Mechanize.log)
first_elem.strip!
key, value = first_elem.split(/=/, 2)

cookie = nil
begin
cookie = new(key, WEBrick::HTTPUtils.dequote(value))
rescue
log.warn("Couldn't parse key/value: #{first_elem}") if log
end
next unless cookie

cookie_elem.each{|pair|
pair.strip!
Expand Down
9 changes: 9 additions & 0 deletions test/test_cookie_class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ def test_parse_dates
end
end

def test_parse_weird_cookie
cookie = 'n/a, ASPSESSIONIDCSRRQDQR=FBLDGHPBNDJCPCGNCPAENELB; path=/'
url = URI.parse('http://www.searchinnovation.com/')
WWW::Mechanize::Cookie.parse(url, cookie) { |cookie|
assert_equal('ASPSESSIONIDCSRRQDQR', cookie.name)
assert_equal('FBLDGHPBNDJCPCGNCPAENELB', cookie.value)
}
end

def test_double_semicolon
double_semi = 'WSIDC=WEST;; domain=.williams-sonoma.com; path=/'
url = URI.parse('http://williams-sonoma.com/')
Expand Down

0 comments on commit 727fa04

Please sign in to comment.