Skip to content

Commit

Permalink
fix: param with escaped periods (#98)
Browse files Browse the repository at this point in the history
close #97
  • Loading branch information
yesmeck committed May 19, 2024
1 parent 99edd20 commit 3673f55
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/wise-pans-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"remix-routes": patch
---

fix: param with escaped periods
3 changes: 3 additions & 0 deletions e2e/app/routes/api.$id[.]json.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export type SearchParams = {

}
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ exports[`build v2 routes 1`] = `
"/api/:id.json": {
params: {
id.json: string | number;
id: string | number;
},
query: ExportedQuery<import('../app/routes/api.$id[.]json').SearchParams>,
Expand Down
4 changes: 4 additions & 0 deletions packages/remix-routes/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ test('$path + params', () => {
expect($path('/posts/:id', { id: 1 })).toBe('/posts/1');
});

test('$path + params + escape periods', () => {
expect($path('/posts/:id.json', { id: 1 })).toBe('/posts/1.json');
});

test('$path + query', () => {
expect($path('/posts', { order: 'desc' })).toBe('/posts?order=desc');
});
Expand Down
1 change: 1 addition & 0 deletions packages/remix-routes/src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ function parse(routes: ConfigRoute[]) {
...route.path
.split('/')
.filter((seg) => seg.startsWith(':') || seg == '*')
.map((param) => param.split('.')[0])
.map((param) => param.replace(':', '').replace('*', '"*"')),
)
);
Expand Down
4 changes: 2 additions & 2 deletions packages/remix-routes/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ export function $path(route: string, ...paramsOrQuery: Array<any>) {
fragment = fragment.slice(0, -1);
}
if (fragment.indexOf(':') > -1) {
let paramName = fragment.slice(1);
let [paramName, extension] = fragment.slice(1).split('.');
if (paramName in params && params[paramName] !== undefined) {
return params[paramName];
return params[paramName] + (extension ? '.' + extension : '');
}
return null
}
Expand Down

0 comments on commit 3673f55

Please sign in to comment.