From 6689b3b7aad15595be90ecd1fb0f256af3215428 Mon Sep 17 00:00:00 2001 From: Akinori MUSHA Date: Sun, 7 Apr 2013 23:09:30 +0900 Subject: [PATCH] Drop support for obsolete attributes: version and comment. --- README.md | 11 +++++++++++ lib/http/cookie.rb | 19 +------------------ lib/http/cookie_jar/cookiestxt_saver.rb | 3 +-- test/test_http_cookie.rb | 2 +- 4 files changed, 14 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 0b8ffb1..3c63667 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,17 @@ equivalent using `HTTP::Cookie`: cookies1 = HTTP::Cookie.parse(set_cookie1, uri_or_url) cookies2 = HTTP::Cookie.parse(set_cookie2, uri_or_url, :logger => log) +- `Mechanize::Cookie#version`, `#version=` + + There is no longer a sense of version in HTTP cookie. The only + version number that has ever been defined was zero, and there will + be no other version since the version attribute has been removed + in RFC 6265. + +- `Mechanize::Cookie#comment`, `#comment=` + + Ditto. The comment attribute has been removed in RFC 6265. + - `Mechanize::Cookie#set_domain` # before diff --git a/lib/http/cookie.rb b/lib/http/cookie.rb index 68555be..97c1342 100644 --- a/lib/http/cookie.rb +++ b/lib/http/cookie.rb @@ -158,11 +158,8 @@ class HTTP::Cookie # new("name" => "uid", "value" => "a12345", "Domain" => 'www.example.org') # def initialize(*args) - @version = 0 # Netscape Cookie - @origin = @domain = @path = - @expires = @max_age = - @comment = nil + @expires = @max_age = nil @secure = @httponly = false @session = true @created_at = @accessed_at = Time.now @@ -306,10 +303,6 @@ class HTTP::Cookie cookie.expires = avalue unless cookie.max_age when 'max-age' cookie.max_age = avalue - when 'comment' - cookie.comment = avalue - when 'version' - cookie.version = avalue when 'secure' cookie.secure = avalue when 'httponly' @@ -521,13 +514,6 @@ class HTTP::Cookie self end - # The version attribute. The only known version of the cookie - # format is 0. - attr_accessor :version - - # The comment attribute. - attr_accessor :comment - # The time this cookie was created at. This value is used as a base # date for interpreting the Max-Age attribute value. See #expires. attr_accessor :created_at @@ -610,9 +596,6 @@ class HTTP::Cookie elsif @expires string << "; Expires=#{@expires.httpdate}" end - if @comment - string << "; Comment=#{Scanner.quote(@comment)}" - end if @httponly string << "; HttpOnly" end diff --git a/lib/http/cookie_jar/cookiestxt_saver.rb b/lib/http/cookie_jar/cookiestxt_saver.rb index 9f22ca1..aba0123 100644 --- a/lib/http/cookie_jar/cookiestxt_saver.rb +++ b/lib/http/cookie_jar/cookiestxt_saver.rb @@ -80,7 +80,6 @@ class HTTP::CookieJar::CookiestxtSaver < HTTP::CookieJar::AbstractSaver :path => path, :secure => s_secure == True, :httponly => httponly, - :expires => expires, - :version => 0) + :expires => expires) end end diff --git a/test/test_http_cookie.rb b/test/test_http_cookie.rb index db309bb..25d677c 100644 --- a/test/test_http_cookie.rb +++ b/test/test_http_cookie.rb @@ -102,7 +102,6 @@ class TestHTTPCookie < Test::Unit::TestCase assert_equal 1, HTTP::Cookie.parse(cookie_str, uri) { |cookie| assert_equal 'quoted', cookie.name assert_equal 'value', cookie.value - assert_equal 'comment is "comment"', cookie.comment }.size end @@ -127,6 +126,7 @@ class TestHTTPCookie < Test::Unit::TestCase def test_parse_bad_version bad_cookie = 'PRETANET=TGIAqbFXtt; Name=/PRETANET; Path=/; Version=1.2; Content-type=text/html; Domain=192.168.6.196; expires=Friday, 13-November-2026 23:01:46 GMT;' url = URI.parse('http://192.168.6.196/') + # The version attribute is obsolete and simply ignored cookies = HTTP::Cookie.parse(bad_cookie, url) assert_equal 1, cookies.size end