Skip to content

Commit 75a0433

Browse files
authored
allow empty value cookies (#208)
1 parent f8b8de1 commit 75a0433

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

Diff for: Sources/AsyncHTTPClient/HTTPClient+HTTPCookie.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ extension HTTPClient {
5050
return nil
5151
}
5252

53-
let nameAndValue = components[0].split(separator: "=", maxSplits: 1).map {
53+
let nameAndValue = components[0].split(separator: "=", maxSplits: 1, omittingEmptySubsequences: false).map {
5454
$0.trimmingCharacters(in: .whitespaces)
5555
}
5656

Diff for: Tests/AsyncHTTPClientTests/HTTPClientCookieTests+XCTest.swift

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ extension HTTPClientCookieTests {
2626
static var allTests: [(String, (HTTPClientCookieTests) -> () throws -> Void)] {
2727
return [
2828
("testCookie", testCookie),
29+
("testEmptyValueCookie", testEmptyValueCookie),
2930
("testCookieDefaults", testCookieDefaults),
3031
("testCookieInit", testCookieInit),
3132
]

Diff for: Tests/AsyncHTTPClientTests/HTTPClientCookieTests.swift

+13
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,19 @@ class HTTPClientCookieTests: XCTestCase {
3030
XCTAssertTrue(c.secure)
3131
}
3232

33+
func testEmptyValueCookie() {
34+
let v = "cookieValue=; Path=/"
35+
let c = HTTPClient.Cookie(header: v, defaultDomain: "exampe.org")!
36+
XCTAssertEqual("cookieValue", c.name)
37+
XCTAssertEqual("", c.value)
38+
XCTAssertEqual("/", c.path)
39+
XCTAssertEqual("exampe.org", c.domain)
40+
XCTAssertNil(c.expires)
41+
XCTAssertNil(c.maxAge)
42+
XCTAssertFalse(c.httpOnly)
43+
XCTAssertFalse(c.secure)
44+
}
45+
3346
func testCookieDefaults() {
3447
let v = "key=value"
3548
let c = HTTPClient.Cookie(header: v, defaultDomain: "example.org")!

0 commit comments

Comments
 (0)