fix: don't throw when a set-cookie string has no name-value-pair#82
Merged
Conversation
Owner
|
This is now published to npm in v3.1.2 |
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.
parseString(and thereforeparseSetCookie) throws when a Set-Cookie string contains only semicolons/whitespace and no name-value-pair:setCookieValue.split(";").filter(isNonEmptyString)yields an empty array for such input, soparts.shift()isundefinedandparseNameValuePair(undefined)calls.spliton it.This is inconsistent with how the library already handles empty content:
parseSetCookie("")andparseSetCookie(" ")return[], and invalid cookies (e.g. forbidden__proto__names) are dropped rather than throwing. A string that is all semicolons has no name-value-pair, so per RFC 6265 §5.2 it should be ignored, not crash the parser.Fix: return
nullwhen there is no name-value-pair, so it's filtered out exactly like the other ignored-cookie cases.parseSetCookie(";")now returns[],parseSetCookie([";", "foo=bar"])returns just the valid cookie, and{ map: true }returns{}.Adds a regression test.