Commit graph

56 commits

Author SHA1 Message Date
Akinori MUSHA
5b78957e19 Conform to RFC 6265 5.1.4 in that path=/a matches /a/* but not /ab.
Remove HTTP::Cookie.normalize_path and add HTTP::Cookie.path_match?
instead for comparison.
2013-03-23 02:02:56 +09:00
Akinori MUSHA
4cbea79c00 Improve tests for valid_for_uri?. 2013-03-23 01:54:58 +09:00
Akinori MUSHA
d47e2fe8ad Add tests for #path. 2013-03-23 01:39:46 +09:00
Akinori MUSHA
38f7e98f09 Replace compatibility errors with documentation.
Leave compatibility stuff to Mechanize itself and just keep
http-cookie clean.
2013-03-23 00:27:38 +09:00
Akinori MUSHA
ddf74fee1e Rewrite the Set-Cookie header parser entirely.
The new parser is almost RFC 6265 compliant as the previous
implementation but has some extensions:

- It can parse double-quoted values with unsafe characters inside
  escaped with the backslash.

- It parses a date value of the expires attribute in the way the RFC
  describes, with an exception that it allows omission of the seconds
  field.  Some of the broken date representations that used to pass
  are now treated as error and ignored.

- It can parse a Set-Cookie value that contains multiple cookie
  definitions separated by comma, and commas put inside double quotes
  are not mistaken as definition separator.
2013-03-21 15:52:22 +09:00
Akinori MUSHA
66f37b20dd Rename expire to expire!, to reduce the risk of making a typo. 2013-03-21 15:46:45 +09:00
Akinori MUSHA
5d0bc5f67d Disallow some more bad characters in name=/value=. 2013-03-21 15:46:45 +09:00
Akinori MUSHA
cc6780a5bc A relative path must be treated as the root path as per RFC 6265 5.1.4. 2013-03-21 15:46:45 +09:00
Akinori MUSHA
f14c1786cd Make expires and max_age affect each other and drop session=(). 2013-03-21 15:46:45 +09:00
Akinori MUSHA
ceea67add9 Drop multi-byte characters from the test, which are not allowed. 2013-03-21 15:46:45 +09:00
Akinori MUSHA
7d81c10914 A cookie value may be DQUOTE'd as per RFC 6265 2.2.
Escaping with the backslash character is not mentioned in the RFC but
the backslash character is not allowed here anyway, so just be nice
and support it for legacy applications.
2013-03-21 15:46:45 +09:00
Akinori MUSHA
dff0f57614 Delete trailing whitespace. 2013-03-18 00:43:52 +09:00
Akinori MUSHA
9768154e82 Dir.tmpdir should be mktmpdir here. 2013-03-18 00:39:55 +09:00
Akinori MUSHA
c389a52e2c Drop dependency on WEBrick::HTTPUtils. 2013-03-18 00:09:01 +09:00
Akinori MUSHA
6d3f4ee2dd parse() ignores bad cookies. 2013-03-18 00:06:20 +09:00
Akinori MUSHA
4a5eb9801a Test that parse() actually returns a cookie. 2013-03-18 00:05:31 +09:00
Akinori MUSHA
f936d91521 1.8 compatibility: Fix syntax and remove dependency on hash key order. 2013-03-15 12:13:59 +09:00
Akinori MUSHA
b2920eda0f Do not chdir in test. It breaks autoloads since test is run with -Ilib. 2013-03-15 12:12:53 +09:00
Akinori MUSHA
8be03978a0 Make each(uri) not fail if a non-HTTP URL is given.
Fix documents with #each.  The uri argument was not made a keyword
argument.

Guarantee that the +uri+ given to AbstractStore#each() is a URI
object.

Make HashStore#each return self as required.
2013-03-15 11:33:54 +09:00
Akinori MUSHA
b86690cb21 Check if the scheme is http(s) and the host is non-nil in URI. 2013-03-15 11:21:57 +09:00
Akinori MUSHA
c0d5f3a121 Add error messages to make migration from Mechanize::Cookie easier.
Add a section to elaborate on the incompatibilities to README.md.
2013-03-15 05:53:11 +09:00
Akinori MUSHA
8d8f01fa81 Cap the numbers of cookies per domain and cookies total, respectively.
This is implemented in HashStore#cleanup(), which is automatically
called by #add() after every 150 updates.
2013-03-15 04:20:59 +09:00
Akinori MUSHA
1f5eb6bc7f Introduce an abstraction layer for saving (serializing) CookieJar.
CookieJar#save is the new name for the now obsolete #save_as.

CookieJar#save and #load now accept IO-like instead of a filename.

Change the YAML file format, and make #load discard incompatible data.
2013-03-15 04:20:59 +09:00
Akinori MUSHA
fd7450717a Implement HTTP::CookieJar#empty? without an argument. 2013-03-15 04:20:59 +09:00
Akinori MUSHA
3b38cd2ffd Use multi-assignment. 2013-03-15 04:20:59 +09:00
Akinori MUSHA
a831fc424c Add HTTP::Cookie#set_cookie_value, and alias #cookie_value to #to_s. 2013-03-15 04:20:59 +09:00
Akinori MUSHA
1fcf008cf0 Make HTTP::Cookie#expired? optionally take a time. 2013-03-15 04:20:59 +09:00
Akinori MUSHA
d8be652a92 Add HTTP::Cookie#expire. 2013-03-15 04:20:58 +09:00
Akinori MUSHA
91193dace3 Fix saving in the cookies.txt format. Expires values were broken.
Remove duplicate and incomplete tests.
2013-03-15 04:20:58 +09:00
Akinori MUSHA
84d375e3b7 Make HTTP::Cookie.parse() reject cookies longer than 4096 bytes.
This limit is defined as HTTP::Cookie::MAX_LENGTH.
2013-03-15 04:20:58 +09:00
Akinori MUSHA
10e9ca5c60 Add HTTP::Cookie#session? as an alias for #session. 2013-03-15 04:20:58 +09:00
Akinori MUSHA
9d842404e3 Fix <=> so that two cookies of different values are not equal. 2013-03-12 18:32:18 +09:00
Akinori MUSHA
ea4759bd27 Add a test for <=>. 2013-03-12 18:32:18 +09:00
Akinori MUSHA
7554bffb32 Allow passing a base time to HTTP::Cookie.parse() via :date. 2013-03-12 18:32:18 +09:00
Akinori MUSHA
6d8fb94f83 Add support for the HttpOnly attribute.
New methods are added to HTTP::Cookie: httponly?, httponly=
2013-03-12 18:32:18 +09:00
Akinori MUSHA
2af7ffa907 Refactor the test code. 2013-03-12 18:32:18 +09:00
Akinori MUSHA
3c6659f43a Enable code coverage. 2012-11-06 01:12:29 +09:00
Akinori MUSHA
4bb4d51f8d Use a newer version of test-unit. 2012-11-06 00:05:09 +09:00
Akinori MUSHA
1731b155e6 HTTP::CookieJar#add: Check if both the domain and path of the cookie are set. 2012-10-22 14:50:49 +09:00
Akinori MUSHA
fa45e028a7 Treat an empty path as '/'.
HTTP::CookieJar#cookies: Do not modify a given URI.  Remove a
redundant cleanup() call.
2012-10-22 14:21:46 +09:00
Akinori MUSHA
a47a849387 Define HTTP::Cookie#name= with validation. 2012-10-22 03:52:25 +09:00
Akinori MUSHA
fdcdae34be Make test_save_and_read_cookiestxt better. 2012-10-22 03:29:32 +09:00
Akinori MUSHA
95c702f99b Rename HTTP::CookieJar#add! to HTTP::CookieJar#add removing the original #add. 2012-10-22 02:39:20 +09:00
Akinori MUSHA
a342680e4e Fix and move some tests from test_http_cookie_jar.rb to test_http_cookie.rb. 2012-10-22 02:38:08 +09:00
Akinori MUSHA
ae4a9d8d40 Make HTTP::Cookie Comparable. 2012-10-22 01:02:00 +09:00
Akinori MUSHA
53e5b270ee Improve test_save_cookies_yaml(). 2012-10-22 00:04:53 +09:00
Akinori MUSHA
aa64d3d98b Rename HTTP::Cookie#clear! to clear. 2012-10-21 23:48:57 +09:00
Akinori MUSHA
dd3ca9a0f1 Inhibit a domain-less cookie from being used for checking validity. 2012-10-18 19:00:33 +09:00
Akinori MUSHA
75f7ee6505 Make valid_for_uri? and acceptable_from_uri? accept a URL string also. 2012-10-18 18:57:46 +09:00
Akinori MUSHA
e010e8f30e Add tests for valid_for_uri?. 2012-10-18 18:52:06 +09:00