Skip to content

Commit

Permalink
encode api url components (#1604)
Browse files Browse the repository at this point in the history
* encode api url components

* Create thin-swans-yell.md

---------

Co-authored-by: Ryan Carniato <ryansolid@gmail.com>
  • Loading branch information
rvlzzr and ryansolid authored Aug 21, 2024
1 parent 516eb82 commit 7ae221b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/thin-swans-yell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@solidjs/start": patch
---

encode api url components
2 changes: 1 addition & 1 deletion packages/start/src/router/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
Expand Down

0 comments on commit 7ae221b

Please sign in to comment.