-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Fix parsing complex accept headers #2603
Conversation
if aq == bq { | ||
return .orderedSame | ||
} else if aq > bq { | ||
return .orderedAscending | ||
} else { | ||
return .orderedDescending | ||
} else { | ||
return .orderedAscending |
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.
This was twisted - as aq
is the left hand side input parameter the return value should be .orderedDescending
when larger than the right hand side.
self.pop() | ||
} else if let comma = self.current.firstIndex(of: .comma) { | ||
value = self.pop(to: comma) | ||
} else if let separatorMatch = self.firstIndex(matchingAnyOf: .comma, .semicolon) { |
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.
Instead of always preferring semicolon
first we also check if there are comma
along the way.
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.
Thanks for doing this! Just a couple of changes around shoring up the tests and we're good to go!
|
||
// Simple accept type | ||
do { | ||
headers.replaceOrAdd(name: .accept, value: "text/html") |
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.
Just for complete sanity and to avoid future regressions could you add an assert to these tests that ensures that the accepted media types match the ones in the header. E.g.
XCTAssertTrue(headers.accept.mediaTypes.contains(.html))
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.
Thanks for the feedback. I've added some cases + removed the catchall from the second, more complex test to allow testing for concrete types…
…or into bugfix/complex-accept-headers
Original comment: Fixes #2283 This PR fixes an issue that parsing more complex accept headers like text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8 failed. When adding unit tests for those more complex accept headers I realized that also the logic in HTTPMediaTypePreference.swift for comparing two media types is incorrect. I fixed this along the way and also added a test for this |
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.
Thanks!
These changes are now available in 4.44.1 |
Fixes an issue when parsing complex
Accept
headers, e.g.text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
The accept header should now be correctly parsed and all accepted types available. Also fixes an issue inHTTPMediaTypePreference
when comparing two media types. (#2603)Fixes #2283