Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
21 changes: 16 additions & 5 deletions packages/playwright-core/src/utils/isomorphic/urlMatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,23 +127,34 @@ function resolveGlobBase(baseURL: string | undefined, match: string): string {
}
// Escaped `\\?` behaves the same as `?` in our glob patterns.
match = match.replaceAll(/\\\\\?/g, '?');
// Node URL constructors automatically uses colon as an indicator of a base URL, such as with `about:blank`
// Only perform special handling if we have a specified base URL
let ignoreBaseURL = false;
// Glob symbols may be escaped in the URL and some of them such as ? affect resolution,
// so we replace them with safe components first.
const relativePath = match.split('/').map((token, index) => {
if (token === '.' || token === '..' || token === '')
return token;
// Handle special case of http*://, note that the new schema has to be
// a web schema so that slashes are properly inserted after domain.
if (index === 0 && token.endsWith(':'))
return mapToken(token, 'http:');
if (index === 0) {
// Handle special case of http*://, note that the new schema has to be
// a web schema so that slashes are properly inserted after domain.
if (token.endsWith(':')) {
return mapToken(token, 'http:');
} else if (token.indexOf(':') !== -1) {
// First token wasn't of the form /\w+:\//, but it still contains a colon
// Node URL constructors automatically uses colon as an indicator of a base URL, such as with `about:blank`
// Ignore baseURL but tokenize normally
ignoreBaseURL = true;
}
}
const questionIndex = token.indexOf('?');
if (questionIndex === -1)
return mapToken(token, `$_${index}_$`);
const newPrefix = mapToken(token.substring(0, questionIndex), `$_${index}_$`);
const newSuffix = mapToken(token.substring(questionIndex), `?$_${index}_$`);
return newPrefix + newSuffix;
}).join('/');
let resolved = constructURLBasedOnBaseURL(baseURL, relativePath);
let resolved = constructURLBasedOnBaseURL(!ignoreBaseURL ? baseURL : undefined, relativePath);
for (const [token, original] of tokenMap)
resolved = resolved.replace(token, original);
match = resolved;
Expand Down
6 changes: 6 additions & 0 deletions tests/page/interception.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ it('should work with glob', async () => {
expect(urlMatches('http://playwright.dev/foo', 'http://playwright.dev/foo?bar', '\\\\?bar')).toBeTruthy();
expect(urlMatches('http://first.host/', 'http://second.host/foo', '**/foo')).toBeTruthy();
expect(urlMatches('http://playwright.dev/', 'http://localhost/', '*//localhost/')).toBeTruthy();

expect(urlMatches('http://playwright.dev/', 'about:blank', 'about:blank')).toBeTruthy();
expect(urlMatches('http://playwright.dev/', 'about:blank', 'http://playwright.dev/')).toBeFalsy();
expect(urlMatches(undefined, 'about:blank', 'about:blank')).toBeTruthy();
expect(urlMatches(undefined, 'about:blank', 'about:*')).toBeTruthy();
expect(urlMatches(undefined, 'notabout:blank', 'about:*')).toBeFalsy();
});

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