Skip to content

Commit 91c3545

Browse files
committed
fix(core): handle ${} in getRoutePath and escaped tags in getRouteAsArray
getRoutePath: skip past ${...} block and continue processing remaining suffix so later {param} segments are still converted. getRouteAsArray: add (?<!\) to split/match regexes so jsesc-escaped ${...} is treated as literal text, preventing standalone backslash from breaking single-quote wrapping.
1 parent b1e21fa commit 91c3545

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

packages/core/src/getters/route.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,15 @@ const getRoutePath = (path: string): string => {
3737
// Don't treat ${...} as a path param — OpenAPI params use {param}, not
3838
// ${param}. After jsesc boundary escaping, ${ becomes \${, but the { is
3939
// still visible to the regex below and would be misinterpreted as a param.
40+
// Skip past the ${...} block and continue processing the remaining suffix.
4041
const braceIdx = path.indexOf('{');
4142
if (braceIdx > 0 && path[braceIdx - 1] === '$') {
42-
return path;
43+
const closeIdx = path.indexOf('}', braceIdx);
44+
if (closeIdx === -1) return path;
45+
const rest = path.slice(closeIdx + 1);
46+
return hasParam(rest)
47+
? `${path.slice(0, closeIdx + 1)}${getRoutePath(rest)}`
48+
: path;
4349
}
4450

4551
const matches = /([^{]*){?([\w*_-]*)}?(.*)/.exec(path);
@@ -192,12 +198,13 @@ export function getRouteAsArray(route: string): string {
192198
if (!segment.includes('${')) {
193199
return [`'${segment.replaceAll("'", "\\'")}'`];
194200
}
195-
// Split by template tags, keeping the delimiters
201+
// Split by template tags, keeping the delimiters.
202+
// (?<!\\) prevents matching \${...} (jsesc-escaped) as a template tag.
196203
return segment
197-
.split(/(\$\{.+?\})/g)
204+
.split(/(?<!\\)(\$\{.+?\})/g)
198205
.filter(Boolean)
199206
.map((part) => {
200-
const match = /^\$\{(.+?)\}$/.exec(part);
207+
const match = /^(?<!\\)\$\{(.+?)\}$/.exec(part);
201208
return match ? match[1] : `'${part.replaceAll("'", "\\'")}'`;
202209
});
203210
})

0 commit comments

Comments
 (0)