Skip to content

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

Merged
merged 1 commit into from
Jul 5, 2019

Conversation

drodriguez
Copy link
Contributor

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.

@pushkarnk
Copy link
Member

@swift-ci please test

@drodriguez
Copy link
Contributor Author

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).

@drodriguez drodriguez force-pushed the cookies-comma-handling branch from f323413 to 07dde3c Compare June 25, 2019 17:31
@drodriguez
Copy link
Contributor Author

@swift-ci please test Linux platform

@drodriguez drodriguez force-pushed the cookies-comma-handling branch from 07dde3c to 11d3338 Compare June 25, 2019 20:43
@drodriguez
Copy link
Contributor Author

@swift-ci please test Linux platform

@@ -497,7 +535,7 @@ open class HTTPCookie : NSObject {
let name = pair.components(separatedBy: "=")[0]
let value = pair.components(separatedBy: "\(name)=")[1]
Copy link
Contributor

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")
}
}

Copy link
Contributor

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.

@drodriguez
Copy link
Contributor Author

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

@drodriguez drodriguez force-pushed the cookies-comma-handling branch from 11d3338 to f6a9c4f Compare June 27, 2019 01:16
@drodriguez
Copy link
Contributor Author

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

@drodriguez
Copy link
Contributor Author

@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.
@drodriguez drodriguez force-pushed the cookies-comma-handling branch from f6a9c4f to 0faf933 Compare June 28, 2019 22:29
@drodriguez
Copy link
Contributor Author

drodriguez commented Jun 28, 2019

Added the tests I promised for yesterday. Fixed some pieces to match better macOS Foundation.

@drodriguez
Copy link
Contributor Author

@swift-ci please test Linux platform

@millenomi millenomi merged commit 7dba88d into swiftlang:master Jul 5, 2019
@drodriguez drodriguez deleted the cookies-comma-handling branch July 8, 2019 23:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants