This repository was archived by the owner on Feb 10, 2024. It is now read-only.
fix: parseCookies error when cookie value has '=' - #339
Open
yes1am wants to merge 1 commit into
Open
Conversation
Akolyte01
reviewed
Jan 6, 2023
| }); | ||
| const pairs = s.split(';') | ||
|
|
||
| for (let i = 0; i < pairs.length; i++) { |
There was a problem hiding this comment.
you are only using i to get the pair. Why not use forEach here?
s.split(';').forEach((pair) => {
const index = pair.indexOf('='):
// rest of the logic
});
Author
There was a problem hiding this comment.
In fact, I was copying the code from here and thought it would solve my problem and also pass the all tests: https://github.com/jshttp/cookie/blob/04be428b438605b48ad6af503227b817c07b9b52/index.js#L48-L82
| const value = decodeURIComponent(encodedValue); | ||
| parsed[key] = value; | ||
| }); | ||
| const pairs = s.split(';') |
There was a problem hiding this comment.
Doesn't this just change the bug from breaking with '=' values to breaking with ';' values?
| const key = pair.substring(0, index).trim() | ||
|
|
||
| // only assign once | ||
| if (undefined == parsed[key]) { |
Akolyte01
reviewed
Jan 6, 2023
|
|
||
| for (let i = 0; i < pairs.length; i++) { | ||
| const pair = pairs[i]; | ||
| const index = pair.indexOf('=') |
There was a problem hiding this comment.
this logic could be simplified using split with a limit
const [key, val] = pair.split('=', 2);
if (val === undefined) {
continue;
}
Akolyte01
reviewed
Jan 6, 2023
| let val = pair.substring(index + 1, pair.length).trim() | ||
|
|
||
| // quoted values | ||
| if (val[0] === '"') { |
There was a problem hiding this comment.
doesn't look like the previous implementation does this. What use case is this for?
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.

fix issue: #338