From 3972c20a5a60b311717de9ca2071d3cc14ddae6a Mon Sep 17 00:00:00 2001 From: ZacharyZcR Date: Sun, 5 Oct 2025 21:44:04 +0800 Subject: [PATCH] fix: remove unnecessary escape characters in regex patterns MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 移除了正则表达式中不必要的转义字符: - users.ts: 修复 5 个 \/ 不必要的转义 - TabContext.tsx: 修复 1 个 \/ 不必要的转义 在字符串形式的正则表达式中,/ 不需要转义。 --- src/backend/database/routes/users.ts | 13 +++++-------- src/ui/Desktop/Navigation/Tabs/TabContext.tsx | 2 +- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/backend/database/routes/users.ts b/src/backend/database/routes/users.ts index f7a7c066..c70676cc 100644 --- a/src/backend/database/routes/users.ts +++ b/src/backend/database/routes/users.ts @@ -34,14 +34,14 @@ async function verifyOIDCToken( const possibleIssuers = [ issuerUrl, normalizedIssuerUrl, - issuerUrl.replace(/\/application\/o\/[^\/]+$/, ""), - normalizedIssuerUrl.replace(/\/application\/o\/[^\/]+$/, ""), + issuerUrl.replace(/\/application\/o\/[^/]+$/, ""), + normalizedIssuerUrl.replace(/\/application\/o\/[^/]+$/, ""), ]; const jwksUrls = [ `${normalizedIssuerUrl}/.well-known/jwks.json`, `${normalizedIssuerUrl}/jwks/`, - `${normalizedIssuerUrl.replace(/\/application\/o\/[^\/]+$/, "")}/.well-known/jwks.json`, + `${normalizedIssuerUrl.replace(/\/application\/o\/[^/]+$/, "")}/.well-known/jwks.json`, ]; try { @@ -491,7 +491,7 @@ router.get("/oidc/authorize", async (req, res) => { let origin = req.get("Origin") || - req.get("Referer")?.replace(/\/[^\/]*$/, "") || + req.get("Referer")?.replace(/\/[^/]*$/, "") || "http://localhost:5173"; if (origin.includes("localhost")) { @@ -598,10 +598,7 @@ router.get("/oidc/callback", async (req, res) => { const normalizedIssuerUrl = config.issuer_url.endsWith("/") ? config.issuer_url.slice(0, -1) : config.issuer_url; - const baseUrl = normalizedIssuerUrl.replace( - /\/application\/o\/[^\/]+$/, - "", - ); + const baseUrl = normalizedIssuerUrl.replace(/\/application\/o\/[^/]+$/, ""); try { const discoveryUrl = `${normalizedIssuerUrl}/.well-known/openid-configuration`; diff --git a/src/ui/Desktop/Navigation/Tabs/TabContext.tsx b/src/ui/Desktop/Navigation/Tabs/TabContext.tsx index 42b9b885..0f5d6d32 100644 --- a/src/ui/Desktop/Navigation/Tabs/TabContext.tsx +++ b/src/ui/Desktop/Navigation/Tabs/TabContext.tsx @@ -69,7 +69,7 @@ export function TabProvider({ children }: TabProviderProps) { } const m = t.title.match( new RegExp( - `^${root.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&")} \\((\\d+)\\)$`, + `^${root.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&")} \\((\\d+)\\)$`, ), ); if (m) {