Skip to content

Remove two-digit year cookie format support & unit test (fails on Ubu… #1707

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions Foundation/HTTPCookie.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,8 @@ open class HTTPCookie : NSObject {
return formatter
}()

// Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036
static let _formatter2: DateFormatter = {
let formatter = DateFormatter()
formatter.locale = Locale(identifier: "en_US_POSIX")
formatter.dateFormat = "EEEE, dd-MMM-yy HH:mm:ss O"
formatter.timeZone = TimeZone(abbreviation: "GMT")
return formatter
}()

// Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() format
static let _formatter3: DateFormatter = {
static let _formatter2: DateFormatter = {
let formatter = DateFormatter()
formatter.locale = Locale(identifier: "en_US_POSIX")
formatter.dateFormat = "EEE MMM d HH:mm:ss yyyy"
Expand All @@ -123,7 +114,7 @@ open class HTTPCookie : NSObject {
}()

// Sun, 06-Nov-1994 08:49:37 GMT ; Tomcat servers sometimes return cookies in this format
static let _formatter4: DateFormatter = {
static let _formatter3: DateFormatter = {
let formatter = DateFormatter()
formatter.locale = Locale(identifier: "en_US_POSIX")
formatter.dateFormat = "EEE, dd-MMM-yyyy HH:mm:ss O"
Expand All @@ -132,7 +123,7 @@ open class HTTPCookie : NSObject {
}()

static let _allFormatters: [DateFormatter]
= [_formatter1, _formatter2, _formatter3, _formatter4]
= [_formatter1, _formatter2, _formatter3]

static let _attributes: [HTTPCookiePropertyKey]
= [.name, .value, .originURL, .version, .domain,
Expand Down
7 changes: 3 additions & 4 deletions TestFoundation/TestHTTPCookie.swift
Original file line number Diff line number Diff line change
Expand Up @@ -175,17 +175,16 @@ class TestHTTPCookie: XCTestCase {
let cookieString =
"""
format1=true; expires=Wed, 01 Jan 2020 12:30:00 GMT; path=/; domain=swift.org; secure; httponly,
format2=true; expires=Wednesday, 01-Jan-20 12:30:00 GMT; path=/; domain=swift.org; secure; httponly,
format3=true; expires=Wed Jan 1 12:30:00 2020; path=/; domain=swift.org; secure; httponly,
format4=true; expires=Wed, 01-Jan-2020 12:30:00 GMT; path=/; domain=swift.org; secure; httponly
format2=true; expires=Wed Jan 1 12:30:00 2020; path=/; domain=swift.org; secure; httponly,
format3=true; expires=Wed, 01-Jan-2020 12:30:00 GMT; path=/; domain=swift.org; secure; httponly
"""

let header = ["header1":"value1",
"Set-Cookie": cookieString,
"header2":"value2",
"header3":"value3"]
let cookies = HTTPCookie.cookies(withResponseHeaderFields: header, for: URL(string: "https://swift.org")!)
XCTAssertEqual(cookies.count, 4)
XCTAssertEqual(cookies.count, 3)
cookies.forEach { cookie in
XCTAssertEqual(cookie.expiresDate, testDate)
XCTAssertEqual(cookie.domain, "swift.org")
Expand Down