Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
fix(glob): /**/ should match single / (#37996)
Yury Semikhatsky2d770a5bfc4a
diff --git a/packages/playwright-core/src/utils/isomorphic/urlMatch.ts b/packages/playwright-core/src/utils/isomorphic/urlMatch.tsindex e4b0cc6edc..00cdfc019b 100644--- a/packages/playwright-core/src/utils/isomorphic/urlMatch.ts+++ b/packages/playwright-core/src/utils/isomorphic/urlMatch.ts@@ -30,15 +30,27 @@ export function globToRegexPattern(glob: string): string {continue;}if (c === '*') {+ const charBefore = glob[i - 1];let starCount = 1;while (glob[i + 1] === '*') {starCount++;i++;}- if (starCount > 1)- tokens.push('(.*)');- else+ if (starCount > 1) {+ const charAfter = glob[i + 1];+ // Match either /..something../ or /.+ if (charAfter === '/') {+ if (charBefore === '/')+ tokens.push('((.+/)|)');+ else+ tokens.push('(.*/)');+ ++i;+ } else {+ tokens.push('(.*)');+ }+ } else {tokens.push('([^/]*)');+ }continue;}diff --git a/tests/page/interception.spec.ts b/tests/page/interception.spec.tsindex a0ef182de1..a1df9ec645 100644--- a/tests/page/interception.spec.ts+++ b/tests/page/interception.spec.ts@@ -92,6 +92,10 @@ it('should work with glob', async () => {expect(globToRegex('http://localhost:3000/signin-oidc*').test('http://localhost:3000/signin-oidc/foo')).toBeFalsy();expect(globToRegex('http://localhost:3000/signin-oidc*').test('http://localhost:3000/signin-oidcnice')).toBeTruthy();+ expect(globToRegex('**/*.js').test('/foo.js')).toBeTruthy();+ expect(globToRegex('asd/**.js').test('/foo.js')).toBeFalsy();+ expect(globToRegex('**/*.js').test('bar_foo.js')).toBeFalsy();+// range [] is NOT supportedexpect(globToRegex('**/api/v[0-9]').test('http://example.com/api/v[0-9]')).toBeTruthy();expect(globToRegex('**/api/v[0-9]').test('http://example.com/api/version')).toBeFalsy();@@ -146,6 +150,10 @@ it('should work with glob', async () => {expect(urlMatches('http://first.host/', 'http://second.host/foo', '**/foo')).toBeTruthy();expect(urlMatches('http://playwright.dev/', 'http://localhost/', '*//localhost/')).toBeTruthy();+ // /**/ should match /.+ expect(urlMatches(undefined, 'https://foo/bar.js', 'https://foo/**/bar.js')).toBeTruthy();+ expect(urlMatches(undefined, 'https://foo/bar.js', 'https://foo/**/**/bar.js')).toBeTruthy();+const customPrefixes = ['about', 'data', 'chrome', 'edge', 'file'];for (const prefix of customPrefixes) {expect(urlMatches('http://playwright.dev/', `${prefix}:blank`, `${prefix}:blank`)).toBeTruthy();