Skip to content

Root-level catch-all /** captures only the first path segment #1

Open

Description

@trackoor

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.mjs

Actual:

{"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/

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions