From 4bce210ff560f08e9358603520471b3658676fa0 Mon Sep 17 00:00:00 2001 From: Owen Date: Sun, 9 Feb 2025 22:03:18 -0500 Subject: [PATCH] Be more lenient with leading and trailing slashes --- server/routers/badger/verifySession.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/server/routers/badger/verifySession.ts b/server/routers/badger/verifySession.ts index a3c6abbc..a65b24a0 100644 --- a/server/routers/badger/verifySession.ts +++ b/server/routers/badger/verifySession.ts @@ -529,8 +529,8 @@ async function checkRules( } function urlGlobToRegex(pattern: string): RegExp { - // Remove leading slash if present (we'll add it to the regex pattern) - pattern = pattern.startsWith("/") ? pattern.slice(1) : pattern; + // Trim any leading or trailing slashes + pattern = pattern.replace(/^\/+|\/+$/g, ""); // Escape special regex characters except * const escapedPattern = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&"); @@ -540,6 +540,7 @@ function urlGlobToRegex(pattern: string): RegExp { // Create the final pattern that: // 1. Optionally matches leading slash - // 2. Matches the entire string - return new RegExp(`^/?${regexPattern}$`); -} + // 2. Matches the pattern + // 3. Optionally matches trailing slash + return new RegExp(`^/?${regexPattern}/?$`); +} \ No newline at end of file