Skip to content

Commit 3401a18

Browse files
authored
fix(url): add more custom prefixes captured by URL globbing (#36579)
1 parent 3fc31ff commit 3401a18

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,9 @@ function resolveGlobBase(baseURL: string | undefined, match: string): string {
128128
// Escaped `\\?` behaves the same as `?` in our glob patterns.
129129
match = match.replaceAll(/\\\\\?/g, '?');
130130
// Special case about: URLs as they are not relative to baseURL
131-
if (match.startsWith('about:'))
131+
if (match.startsWith('about:') || match.startsWith('data:')
132+
|| match.startsWith('chrome:') || match.startsWith('edge:')
133+
|| match.startsWith('file:'))
132134
return match;
133135
// Glob symbols may be escaped in the URL and some of them such as ? affect resolution,
134136
// so we replace them with safe components first.

tests/page/interception.spec.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,14 @@ it('should work with glob', async () => {
129129
expect(urlMatches('http://first.host/', 'http://second.host/foo', '**/foo')).toBeTruthy();
130130
expect(urlMatches('http://playwright.dev/', 'http://localhost/', '*//localhost/')).toBeTruthy();
131131

132-
expect(urlMatches('http://playwright.dev/', 'about:blank', 'about:blank')).toBeTruthy();
133-
expect(urlMatches('http://playwright.dev/', 'about:blank', 'http://playwright.dev/')).toBeFalsy();
134-
expect(urlMatches(undefined, 'about:blank', 'about:blank')).toBeTruthy();
135-
expect(urlMatches(undefined, 'about:blank', 'about:*')).toBeTruthy();
136-
expect(urlMatches(undefined, 'notabout:blank', 'about:*')).toBeFalsy();
132+
const customPrefixes = ['about', 'data', 'chrome', 'edge', 'file'];
133+
for (const prefix of customPrefixes) {
134+
expect(urlMatches('http://playwright.dev/', `${prefix}:blank`, `${prefix}:blank`)).toBeTruthy();
135+
expect(urlMatches('http://playwright.dev/', `${prefix}:blank`, `http://playwright.dev/`)).toBeFalsy();
136+
expect(urlMatches(undefined, `${prefix}:blank`, `${prefix}:blank`)).toBeTruthy();
137+
expect(urlMatches(undefined, `${prefix}:blank`, `${prefix}:*`)).toBeTruthy();
138+
expect(urlMatches(undefined, `not${prefix}:blank`, `${prefix}:*`)).toBeFalsy();
139+
}
137140
});
138141

139142
it('should intercept by glob', async function({ page, server, isAndroid }) {

0 commit comments

Comments
 (0)