Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions packages/playwright-core/src/utils/isomorphic/urlMatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
8 changes: 8 additions & 0 deletions tests/page/interception.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 supported
expect(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();
Expand Down Expand Up @@ -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();
Expand Down
Loading