Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix: align glob ** pattern matching with docs (#37156)

Yury Semikhatsky9f39b39cbe1f
diff --git a/packages/playwright-core/src/utils/isomorphic/urlMatch.ts b/packages/playwright-core/src/utils/isomorphic/urlMatch.ts
index 84fcf8434a..b526ca732e 100644
--- a/packages/playwright-core/src/utils/isomorphic/urlMatch.ts
+++ b/packages/playwright-core/src/utils/isomorphic/urlMatch.ts
@@ -30,22 +30,15 @@ export function globToRegexPattern(glob: string): string {
continue;
}
if (c === '*') {
- const beforeDeep = glob[i - 1];
let starCount = 1;
while (glob[i + 1] === '*') {
starCount++;
i++;
}
- const afterDeep = glob[i + 1];
- const isDeep = starCount > 1 &&
- (beforeDeep === '/' || beforeDeep === undefined) &&
- (afterDeep === '/' || afterDeep === undefined);
- if (isDeep) {
- tokens.push('((?:[^/]*(?:\/|$))*)');
- i++;
- } else {
+ if (starCount > 1)
+ tokens.push('(.*)');
+ else
tokens.push('([^/]*)');
- }
continue;
}
diff --git a/tests/page/interception.spec.ts b/tests/page/interception.spec.ts
index 08c502e9e1..b8653f9ef3 100644
--- a/tests/page/interception.spec.ts
+++ b/tests/page/interception.spec.ts
@@ -123,6 +123,10 @@ it('should work with glob', async () => {
expect(urlMatches(undefined, 'https://playwright.dev/foobar', 'https://playwright.dev/fooBAR')).toBeFalsy();
expect(urlMatches(undefined, 'https://playwright.dev/foobar?a=b', 'https://playwright.dev/foobar?A=B')).toBeFalsy();
+ expect(urlMatches(undefined, 'https://localhost:3000/?a=b', '**/?a=b')).toBeTruthy();
+ expect(urlMatches(undefined, 'https://localhost:3000/?a=b', '**?a=b')).toBeTruthy();
+ expect(urlMatches(undefined, 'https://localhost:3000/?a=b', '**=b')).toBeTruthy();
+
// This is not supported, we treat ? as a query separator.
expect(globToRegex('http://localhost:8080/?imple/path.js').test('http://localhost:8080/Simple/path.js')).toBeFalsy();
expect(urlMatches(undefined, 'http://playwright.dev/', 'http://playwright.?ev')).toBeFalsy();