Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix: hostname match is case insensitive (#37018)

Yury Semikhatsky247fe62876fd
diff --git a/packages/playwright-core/src/utils/isomorphic/urlMatch.ts b/packages/playwright-core/src/utils/isomorphic/urlMatch.ts
index 3741303c83..27003c25e9 100644
--- a/packages/playwright-core/src/utils/isomorphic/urlMatch.ts
+++ b/packages/playwright-core/src/utils/isomorphic/urlMatch.ts
@@ -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;
@@ -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 };
+ }
+}
diff --git a/tests/page/interception.spec.ts b/tests/page/interception.spec.ts
index 5b677aeb35..08c502e9e1 100644
--- a/tests/page/interception.spec.ts
+++ b/tests/page/interception.spec.ts
@@ -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();