From 92418259a3a20565e363f68eae944766dc02c9a3 Mon Sep 17 00:00:00 2001 From: Stefanos Anagnostou Date: Mon, 20 Oct 2025 21:00:50 +0300 Subject: [PATCH 1/2] fix(testing): Update API URL regex on Playwright --- .changeset/cool-keys-scream.md | 5 +++++ packages/testing/src/playwright/setupClerkTestingToken.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changeset/cool-keys-scream.md diff --git a/.changeset/cool-keys-scream.md b/.changeset/cool-keys-scream.md new file mode 100644 index 00000000000..d736cd88437 --- /dev/null +++ b/.changeset/cool-keys-scream.md @@ -0,0 +1,5 @@ +--- +'@clerk/testing': patch +--- + +Fix Playwright route URL to use RegExp instead of Glob URL pattern diff --git a/packages/testing/src/playwright/setupClerkTestingToken.ts b/packages/testing/src/playwright/setupClerkTestingToken.ts index 5b25bb6b06d..f6392961703 100644 --- a/packages/testing/src/playwright/setupClerkTestingToken.ts +++ b/packages/testing/src/playwright/setupClerkTestingToken.ts @@ -38,7 +38,7 @@ export const setupClerkTestingToken = async ({ context, options, page }: SetupCl if (!fapiUrl) { throw new Error(ERROR_MISSING_FRONTEND_API_URL); } - const apiUrl = `https://${fapiUrl}/v1/**/*`; + const apiUrl = new RegExp(`^https://${fapiUrl.replace(/\./g, '\\.')}/v1/.*?(\\?.*)?$`); await browserContext.route(apiUrl, async route => { const originalUrl = new URL(route.request().url()); From 6c1825f46290f032c7a1426548d0d89f876ebed2 Mon Sep 17 00:00:00 2001 From: Stefanos Anagnostou Date: Mon, 20 Oct 2025 21:12:20 +0300 Subject: [PATCH 2/2] escape all risky characters of the fapi url --- packages/testing/src/playwright/setupClerkTestingToken.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/testing/src/playwright/setupClerkTestingToken.ts b/packages/testing/src/playwright/setupClerkTestingToken.ts index f6392961703..5248357f4f6 100644 --- a/packages/testing/src/playwright/setupClerkTestingToken.ts +++ b/packages/testing/src/playwright/setupClerkTestingToken.ts @@ -38,7 +38,9 @@ export const setupClerkTestingToken = async ({ context, options, page }: SetupCl if (!fapiUrl) { throw new Error(ERROR_MISSING_FRONTEND_API_URL); } - const apiUrl = new RegExp(`^https://${fapiUrl.replace(/\./g, '\\.')}/v1/.*?(\\?.*)?$`); + + const escapedFapiUrl = fapiUrl.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); + const apiUrl = new RegExp(`^https://${escapedFapiUrl}/v1/.*?(\\?.*)?$`); await browserContext.route(apiUrl, async route => { const originalUrl = new URL(route.request().url());