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}`); }