Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
fix(routing): match URL globs containing '$$' and other replacement patterns (#41471)
Devin Rousso6b7c40119c23
diff --git a/packages/isomorphic/urlMatch.ts b/packages/isomorphic/urlMatch.tsindex 8a7c106727..20783d1e6f 100644--- a/packages/isomorphic/urlMatch.ts+++ b/packages/isomorphic/urlMatch.ts@@ -249,7 +249,10 @@ function resolveGlobBase(baseURL: string | undefined, match: string): string {let resolved = result.resolved;for (const [token, original] of tokenMap) {const normalize = result.caseInsensitivePart?.includes(token);- resolved = resolved.replace(token, normalize ? original.toLowerCase() : original);+ const replacement = normalize ? original.toLowerCase() : original;+ // '$$', '$&', '$`' and "$'" are special in String.prototype.replace with a string argument.+ // Instead, use the function argument form that treats the string argument literally.+ resolved = resolved.replace(token, () => replacement);}match = resolved;}diff --git a/tests/page/interception.spec.ts b/tests/page/interception.spec.tsindex ca3b6b0494..a0c5c8cebf 100644--- a/tests/page/interception.spec.ts+++ b/tests/page/interception.spec.ts@@ -122,6 +122,11 @@ 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();+ // '$$', '$&', '$`' and "$'" are special in String.prototype.replace with a string argument.+ expect(urlMatches(undefined, 'http://playwright.dev/foo$$bar', 'http://playwright.dev/foo$$bar')).toBeTruthy();+ expect(urlMatches(undefined, 'http://playwright.dev/a$&b', 'http://playwright.dev/a$&b')).toBeTruthy();+ expect(urlMatches('http://playwright.dev', 'http://playwright.dev/p$$q', './p$$q')).toBeTruthy();+// Case insensitive matchingexpect(urlMatches(undefined, 'https://playwright.dev/fooBAR', 'HtTpS://pLaYwRiGhT.dEv/fooBAR')).toBeTruthy();expect(urlMatches('http://ignored', 'https://playwright.dev/fooBAR', 'HtTpS://pLaYwRiGhT.dEv/fooBAR')).toBeTruthy();