Skip to content
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

[BUG] Fix Cookie Parsing Bug for Complex Values #1995

Closed
wants to merge 1 commit into from

Conversation

Grenish
Copy link

@Grenish Grenish commented Aug 28, 2023

Description

This pull request fixes a bug in the parseCookie function that prevented it from correctly handling complex cookie values containing semicolons and equal signs.

Changes Made

  • Updated the parseCookie function to use a more robust approach for splitting and parsing cookies.
  • Used a regular expression to split cookies based on semicolons followed by equal signs.
  • Adjusted the logic to correctly handle complex cookie values containing special characters.

Example

Before this fix:

parseCookie('foo=bar; equation=E%3Dmc%5E2');
// Output: { foo: 'bar', equation: 'E=mc^2' }

After this fix:

parseCookie('foo=bar; equation=E%3Dmc%5E2');
// Output: { foo: 'bar', equation: 'E=mc^2' }

Related Issue

Fixes #1992

@github-actions github-actions bot added js Related to JavaScript content. snippet Related to snippets. labels Aug 28, 2023
@Grenish Grenish changed the title Fixed Error #1992 [BUG] Fix Cookie Parsing Bug for Complex Values Aug 28, 2023
@Chalarangelo
Copy link
Owner

Thanks for putting in the effort, but cookies are meant to be stored without special characters. It's a bad practice to store unencoded equal signs in cookies and it shouldn't be endorsed or shown as an example for beginners. I've explained further under #1992.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
js Related to JavaScript content. snippet Related to snippets.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cookie parsing containing a = in value
2 participants