Repository navigation
Conversation
parse() advanced its position past whitespace as it scanned, so a value followed by whitespace and then a comma was never pushed: 'Origin , Accept-Encoding' parsed to ['accept-encoding'], and a leading '*' was dropped the same way, which left createAddFieldnameToVary unable to see the wildcard. Trim each value as it is sliced and ignore the ones that come out empty, which keeps the existing behaviour for empty segments. Fixes fastify#422
This branch has not been deployed
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.
Fixes #422
parse()drops anyVarytoken that has optional whitespace before its comma:The tokenizer advanced
pospast whitespace as it scanned, so when the comma arrivedpos === iand the value before it was never pushed. The same happened to a leading*:parse('* , foo')returned['foo'], socreateAddFieldnameToVarynever saw the wildcard —which is how the same header also ended up as
'Origin , Accept-Encoding, Origin'.RFC 9110 §5.6.1 allows OWS around the commas of a list, so that whitespace is not part of the
value.
Change
Drop the whitespace branch and trim each value as it is sliced, skipping the ones that come out
empty:
Empty segments behave exactly as before —
'a, , b,c','a,,b,c',',a,b,c'and'a,b,c,'allstill parse to
['a', 'b', 'c'].Tests
Added to
test/vary.test.js:'a ,b','a , b','a , , b'and'* , a'parse to the expected valuescreateAddFieldnameToVarycase showing'Origin , Accept-Encoding'is left untouched whenOriginis added (before this it became'Origin , Accept-Encoding, Origin')npm run test:unitpasses with 100% coverage.