From 9563e9a77128446a9dcc05da505b7ecb9f729c1f Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Mon, 11 Nov 2024 13:44:22 +0100 Subject: [PATCH] fix: scan route files with other chars in param name (#2872) --- src/core/scan.ts | 2 +- test/fixture/api/param/{[id].ts => [test-id].ts} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename test/fixture/api/param/{[id].ts => [test-id].ts} (72%) diff --git a/src/core/scan.ts b/src/core/scan.ts index e04a70704e..d5f53cf1ed 100644 --- a/src/core/scan.ts +++ b/src/core/scan.ts @@ -98,7 +98,7 @@ export async function scanServerRoutes( .replace(/\(([^(/\\]+)\)[/\\]/g, "") .replace(/\[\.{3}]/g, "**") .replace(/\[\.{3}(\w+)]/g, "**:$1") - .replace(/\[(\w+)]/g, ":$1"); + .replace(/\[([^/\]]+)]/g, ":$1"); route = withLeadingSlash(withoutTrailingSlash(withBase(route, prefix))); const suffixMatch = route.match(suffixRegex); diff --git a/test/fixture/api/param/[id].ts b/test/fixture/api/param/[test-id].ts similarity index 72% rename from test/fixture/api/param/[id].ts rename to test/fixture/api/param/[test-id].ts index 86a4d93497..4ec687eaa9 100644 --- a/test/fixture/api/param/[id].ts +++ b/test/fixture/api/param/[test-id].ts @@ -1,4 +1,4 @@ export default eventHandler((event) => { setHeader(event, "Content-Type", "text/plain; charset=utf-16"); - return event.context.params!.id; + return event.context.params!["test-id"]; });