Trim optional whitespace in the Accept-Language q-parameter - #106
Open
gaoflow wants to merge 1 commit into
Open
Conversation
parseLanguage() split the q-parameter without trimming, so a space after the ';' (legal OWS per RFC 7231 sec 5.3.1) left the key as ' q' and the q-value was silently dropped and defaulted to 1. charset, encoding and mediaType already trim the parameter; language did not. 'fr; q=0' now yields [] instead of ['fr'], matching 'fr;q=0'.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
parseLanguage()splits theqparameter without trimming it, unlike the charset, encoding and mediaType parsers. RFC 7231 §5.3.1 allows optional whitespace after the;, soen; q=0.1leaves the key as" q"and theqvalue is silently dropped (defaulting to 1).As a result
en;q=0.9, fr; q=0.1sorts as['fr', 'en'], the reverse of the byte-identicalen;q=0.9, fr;q=0.1. Worse,fr; q=0returns['fr']instead of[]— an explicitq=0rejection bypassed by a single space.charset/encodingreturn[]for that same input.The fix is the
.trim()the three siblings already apply. It was left out oflanguage.jsin 0484c74, the 2019 commit that fixed this same loop in all three parsers. Added a whitespace matrix to the language tests; full suite passes (255).