Skip to content

Commit 3f67e71

Browse files
authored
fix(glob): do not treat custom schema as special (#37851)
1 parent b2236c8 commit 3f67e71

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,13 @@ function resolveGlobBase(baseURL: string | undefined, match: string): string {
132132
return token;
133133
// Handle special case of http*://, note that the new schema has to be
134134
// a web schema so that slashes are properly inserted after domain.
135-
if (index === 0 && token.endsWith(':'))
136-
return mapToken(token, 'http:');
135+
if (index === 0 && token.endsWith(':')) {
136+
// Replace any pattern with http:
137+
if (token.indexOf('*') !== -1 || token.indexOf('{') !== -1)
138+
return mapToken(token, 'http:');
139+
// Preserve explicit schema as is as it may affect trailing slashes after domain.
140+
return token;
141+
}
137142
const questionIndex = token.indexOf('?');
138143
if (questionIndex === -1)
139144
return mapToken(token, `$_${index}_$`);

tests/page/interception.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ it('should work with glob', async () => {
127127
expect(urlMatches(undefined, 'https://localhost:3000/?a=b', '**?a=b')).toBeTruthy();
128128
expect(urlMatches(undefined, 'https://localhost:3000/?a=b', '**=b')).toBeTruthy();
129129

130+
// Custom schema.
131+
expect(urlMatches(undefined, 'my.custom.protocol://foo', 'my.custom.protocol://**')).toBeTruthy();
132+
expect(urlMatches(undefined, 'my.p://foo', 'my.{p,y}://**')).toBeFalsy();
133+
expect(urlMatches(undefined, 'my.p://foo/', 'my.{p,y}://**')).toBeTruthy();
134+
expect(urlMatches(undefined, 'file:///foo/', 'f*e://**')).toBeTruthy();
135+
130136
// This is not supported, we treat ? as a query separator.
131137
expect(globToRegex('http://localhost:8080/?imple/path.js').test('http://localhost:8080/Simple/path.js')).toBeFalsy();
132138
expect(urlMatches(undefined, 'http://playwright.dev/', 'http://playwright.?ev')).toBeFalsy();

0 commit comments

Comments
 (0)