From 7ae221b3090e78d9ba332768b8b47d7aac668f13 Mon Sep 17 00:00:00 2001 From: Anti Revoluzzer Date: Tue, 20 Aug 2024 23:49:01 -0700 Subject: [PATCH] encode api url components (#1604) * encode api url components * Create thin-swans-yell.md --------- Co-authored-by: Ryan Carniato --- .changeset/thin-swans-yell.md | 5 +++++ packages/start/src/router/routes.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changeset/thin-swans-yell.md diff --git a/.changeset/thin-swans-yell.md b/.changeset/thin-swans-yell.md new file mode 100644 index 000000000..5ddc5be6e --- /dev/null +++ b/.changeset/thin-swans-yell.md @@ -0,0 +1,5 @@ +--- +"@solidjs/start": patch +--- + +encode api url components diff --git a/packages/start/src/router/routes.ts b/packages/start/src/router/routes.ts index 14269357e..b82d0af66 100644 --- a/packages/start/src/router/routes.ts +++ b/packages/start/src/router/routes.ts @@ -73,7 +73,7 @@ function containsHTTP(route: Route) { const router = createRouter({ routes: (fileRoutes as unknown as Route[]).reduce((memo, route) => { if (!containsHTTP(route)) return memo; - let path = route.path.replace(/\/\([^)/]+\)/g, "").replace(/\([^)/]+\)/g, "").replace(/\*([^/]*)/g, (_, m) => `**:${m}`); + let path = route.path.replace(/\/\([^)/]+\)/g, "").replace(/\([^)/]+\)/g, "").replace(/\*([^/]*)/g, (_, m) => `**:${m}`).split('/').map(s => (s.startsWith(':') || s.startsWith('*')) ? s : encodeURIComponent(s)).join('/'); if (/:[^/]*\?/g.test(path)) { throw new Error(`Optional parameters are not supported in API routes: ${path}`); }