-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Improve cookie parsing algorithm. #2374
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
Conversation
@swift-ci please test |
I have seen those failures in macOS all the time recently. I don’t think they are related to the PR (neither this, neither #2373). |
f323413
to
07dde3c
Compare
@swift-ci please test Linux platform |
07dde3c
to
11d3338
Compare
@swift-ci please test Linux platform |
Foundation/HTTPCookie.swift
Outdated
@@ -497,7 +535,7 @@ open class HTTPCookie : NSObject { | |||
let name = pair.components(separatedBy: "=")[0] | |||
let value = pair.components(separatedBy: "\(name)=")[1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment above
XCTAssertEqual(cookies[1].name, "BBB") | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably worth adding in some broken cookies and ones where the value part has =
in it to test the parsing. I would also add in XCTAssertEqual(cookies[0].value...
checks to validate the values.
I will try to improve the cookie parsing with the recommendations and add more tests with broken cookies in a later PR. @swift-ci please test Linux platform |
11d3338
to
f6a9c4f
Compare
I finally reused this PR, but I haven't add new tests right now. The current one pass, which is quite good already. I will write better ones tomorrow. @swift-ci please test Linux platform |
@swift-ci please test Linux platform |
While the previous parser dealt with commas, some cases were not correctly handled, like when a comma was in the last attribute before a second cookie. Also, improve the cookie parsing algorithm to match better the RFC. The parser is slightly more strict, and will not allow some malformed cookies to happen anymore. Also trim the names of the cookies to allow spaces before the equal. Add some more tests to improve the coverage and ensure the added pieces are working as supposed.
f6a9c4f
to
0faf933
Compare
Added the tests I promised for yesterday. Fixed some pieces to match better macOS Foundation. |
@swift-ci please test Linux platform |
While the previous parser dealt with commas, some cases were not
correctly handled, like when a comma was in the last attribute before a
second cookie.
Also trim the names of the cookies to allow spaces before the equal.