Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: param with escaped periods #98

Merged
merged 1 commit into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading