Open
Description
A catch-all route registered at the root (/** or /**:rest) returns only the first path segment in params instead of the full remaining path.
// repro.mjs
import { FastRouter } from '@neabyte/fast-router'
const r1 = new FastRouter()
r1.add('GET', '/**:rest', 'handler')
console.log(JSON.stringify(r1.find('GET', '/docs/user/guide.pdf')))
const r2 = new FastRouter()
r2.add('GET', '/**', 'handler')
console.log(JSON.stringify(r2.find('GET', '/a/b/c')))
const r3 = new FastRouter()
r3.add('GET', '/files/**:name', 'handler')
console.log(JSON.stringify(r3.find('GET', '/files/docs/user/guide.pdf')))Run with:
npm install @neabyte/fast-router@0.1.0
node repro.mjsActual:
{"data":"handler","params":{"rest":"docs"}}
{"data":"handler","params":{"_":"a"}}
{"data":"handler","params":{"name":"docs/user/guide.pdf"}}Expected:
{"data":"handler","params":{"rest":"docs/user/guide.pdf"}}
{"data":"handler","params":{"_":"a/b/c"}}
{"data":"handler","params":{"name":"docs/user/guide.pdf"}}Versions: @neabyte/fast-router@0.1.0 (npm and JSR) and main (17bab41), Node.js v26.13.0.
In src/Router.ts, add() records a catch-all parameter at segment index i with paramsMap.push([-i, ...]), and getMatchParams() in src/Shared.ts checks index < 0 to join remaining segments; at i === 0, -0 < 0 is false, so it falls through to segments[0].
Credit: https://ucsbplse.github.io/
Metadata
Metadata
Assignees
Labels
No labels
Activity