Repository navigation
fix(network): match empty string filters in clearCookies - #43114
Closed
Lazizbek Ergashev (lazerg) wants to merge 1 commit into
Closed
Lazizbek Ergashev (lazerg) wants to merge 1 commit into
Lazizbek Ergashev (lazerg) wants to merge 1 commit into
Conversation
Alok Pandey (alok-108)
left a comment
Contributor
There was a problem hiding this comment.
Thanks for picking up #43112 so quickly Lazizbek Ergashev (@lazerg)! The fix is concise and directly resolves the bug.
| export function cookieMatchesClearFilter(cookie: channels.NetworkCookie, options: ClearCookiesOptions): boolean { | ||
| const matches = (prop: 'name' | 'domain' | 'path', value: string | RegExp | undefined) => { | ||
| if (!value) | ||
| if (value === undefined) |
Contributor
There was a problem hiding this comment.
This cleanly aligns cookieMatchesClearFilter with hasClearCookiesFilter on line 124, which already checked options[prop] !== undefined.
| { name: 'session', value: '2', domain: 'one.com', path: '/' }, | ||
| ]); | ||
| await request.clearCookies({ name: '' }); | ||
| expect((await request.cookies()).map(c => c.value)).toEqual(['2']); |
Contributor
There was a problem hiding this comment.
Optional nit: It might be helpful to assert both name and value to explicitly verify that the named session cookie was retained:
expect((await request.cookies()).map(c => ({ name: c.name, value: c.value }))).toEqual([
{ name: 'session', value: '2' }
]);
Contributor
Author
There was a problem hiding this comment.
I kept the value-only check to match the test above. Each cookie has a unique value, so ['2'] can only be session.
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.
Summary
cookieMatchesClearFilter()skipped a filter withif (!value), soclearCookies({ name: '' })matched every cookie and removed all of them instead of only the nameless ones.undefined, which is whathasClearCookiesFilter()already checks. This applies to bothBrowserContext.clearCookies()andAPIRequestContext.clearCookies(). The test usesAPIRequestContext, since browsers do not store or expire nameless cookies consistently.Fixes #43112