Skip to content

Commit 9f39b39

Browse files
authored
fix: align glob ** pattern matching with docs (#37156)
1 parent 4bc9fb3 commit 9f39b39

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

packages/playwright-core/src/utils/isomorphic/urlMatch.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,15 @@ export function globToRegexPattern(glob: string): string {
3030
continue;
3131
}
3232
if (c === '*') {
33-
const beforeDeep = glob[i - 1];
3433
let starCount = 1;
3534
while (glob[i + 1] === '*') {
3635
starCount++;
3736
i++;
3837
}
39-
const afterDeep = glob[i + 1];
40-
const isDeep = starCount > 1 &&
41-
(beforeDeep === '/' || beforeDeep === undefined) &&
42-
(afterDeep === '/' || afterDeep === undefined);
43-
if (isDeep) {
44-
tokens.push('((?:[^/]*(?:\/|$))*)');
45-
i++;
46-
} else {
38+
if (starCount > 1)
39+
tokens.push('(.*)');
40+
else
4741
tokens.push('([^/]*)');
48-
}
4942
continue;
5043
}
5144

tests/page/interception.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ it('should work with glob', async () => {
123123
expect(urlMatches(undefined, 'https://playwright.dev/foobar', 'https://playwright.dev/fooBAR')).toBeFalsy();
124124
expect(urlMatches(undefined, 'https://playwright.dev/foobar?a=b', 'https://playwright.dev/foobar?A=B')).toBeFalsy();
125125

126+
expect(urlMatches(undefined, 'https://localhost:3000/?a=b', '**/?a=b')).toBeTruthy();
127+
expect(urlMatches(undefined, 'https://localhost:3000/?a=b', '**?a=b')).toBeTruthy();
128+
expect(urlMatches(undefined, 'https://localhost:3000/?a=b', '**=b')).toBeTruthy();
129+
126130
// This is not supported, we treat ? as a query separator.
127131
expect(globToRegex('http://localhost:8080/?imple/path.js').test('http://localhost:8080/Simple/path.js')).toBeFalsy();
128132
expect(urlMatches(undefined, 'http://playwright.dev/', 'http://playwright.?ev')).toBeFalsy();

0 commit comments

Comments
 (0)