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
23 changes: 19 additions & 4 deletions packages/playwright-core/src/utils/isomorphic/urlMatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,12 @@ function resolveGlobBase(baseURL: string | undefined, match: string): string {
const newSuffix = mapToken(token.substring(questionIndex), `?$_${index}_$`);
return newPrefix + newSuffix;
}).join('/');
let resolved = constructURLBasedOnBaseURL(baseURL, relativePath);
for (const [token, original] of tokenMap)
resolved = resolved.replace(token, original);
const result = resolveBaseURL(baseURL, relativePath);
let resolved = result.resolved;
for (const [token, original] of tokenMap) {
const normalize = result.caseInsensitivePart?.includes(token);
resolved = resolved.replace(token, normalize ? original.toLowerCase() : original);
}
match = resolved;
}
return match;
Expand All @@ -166,8 +169,20 @@ function parseURL(url: string): URL | null {

export function constructURLBasedOnBaseURL(baseURL: string | undefined, givenURL: string): string {
try {
return (new URL(givenURL, baseURL)).toString();
return resolveBaseURL(baseURL, givenURL).resolved;
} catch (e) {
return givenURL;
}
}

function resolveBaseURL(baseURL: string | undefined, givenURL: string) {
try {
const url = new URL(givenURL, baseURL);
const resolved = url.toString();
// Schema and domain are case-insensitive.
const caseInsensitivePrefix = url.origin;
return { resolved, caseInsensitivePart: caseInsensitivePrefix };
} catch (e) {
return { resolved: givenURL };
}
}
7 changes: 7 additions & 0 deletions tests/page/interception.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ it('should work with glob', async () => {
expect(urlMatches('http://playwright.dev', 'http://playwright.dev/?x=y', '?x=y')).toBeTruthy();
expect(urlMatches('http://playwright.dev/foo/', 'http://playwright.dev/foo/bar?x=y', './bar?x=y')).toBeTruthy();

// Case insensitive matching
expect(urlMatches(undefined, 'https://playwright.dev/fooBAR', 'HtTpS://pLaYwRiGhT.dEv/fooBAR')).toBeTruthy();
expect(urlMatches('http://ignored', 'https://playwright.dev/fooBAR', 'HtTpS://pLaYwRiGhT.dEv/fooBAR')).toBeTruthy();
// Path and search query are case-sensitive
expect(urlMatches(undefined, 'https://playwright.dev/foobar', 'https://playwright.dev/fooBAR')).toBeFalsy();
expect(urlMatches(undefined, 'https://playwright.dev/foobar?a=b', 'https://playwright.dev/foobar?A=B')).toBeFalsy();

// This is not supported, we treat ? as a query separator.
expect(globToRegex('http://localhost:8080/?imple/path.js').test('http://localhost:8080/Simple/path.js')).toBeFalsy();
expect(urlMatches(undefined, 'http://playwright.dev/', 'http://playwright.?ev')).toBeFalsy();
Expand Down
Loading