Skip to content

Commit

Permalink
Merge pull request #814 from btea/task/813-unset-previous-cookie
Browse files Browse the repository at this point in the history
#813@patch: Unset previous cookie.
  • Loading branch information
capricorn86 committed Apr 4, 2023
2 parents c0d06c1 + 6a05edb commit 959317f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/happy-dom/src/cookie/Cookie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default class Cookie {
this.key = match[1].trim();
this.value = match[2];
// Set key is empty if match[2] is undefined.
if (!match[2]) {
if (!match[2] && parts[0][this.key.length] !== '=') {
this.value = this.key;
this.key = '';
}
Expand Down
7 changes: 7 additions & 0 deletions packages/happy-dom/test/nodes/document/Document.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,13 @@ describe('Document', () => {
expect(document.cookie).toBe('');
});

it('Unset previous cookie.', () => {
document.cookie = 'name=Dave; expires=Thu, 01 Jan 2025 00:00:00 GMT;';
expect(document.cookie).toBe('name=Dave');
document.cookie = 'name=; expires=Thu, 01 Jan 1970 00:00:00 GMT;';
expect(document.cookie).toBe('');
});

it('Removes a previously defined cookie if "expires" is in the past, but treats cookies with no value set differently from cookies with a value.', () => {
document.cookie = 'name=value1';
document.cookie = 'name';
Expand Down

0 comments on commit 959317f

Please sign in to comment.