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

params are being joined without / #299

Closed
brc-dd opened this issue Aug 8, 2023 · 1 comment
Closed

params are being joined without / #299

brc-dd opened this issue Aug 8, 2023 · 1 comment

Comments

@brc-dd
Copy link

brc-dd commented Aug 8, 2023

const { compile } = require('path-to-regexp')

const toPath = compile(':splat*')

console.log(toPath({ splat: ['foo', 'bar.md'] })) // 'foobar.md'

const toPath_working = compile('/:splat*')

console.log(toPath_working({ splat: ['foo', 'bar.md'] })) // '/foo/bar.md'

Is the behavior in first case expected? I think it should've yielded 'foo/bar.md' 👀

@brc-dd brc-dd changed the title params are being merged without / params are being joined without / Aug 8, 2023
@blakeembrey
Copy link
Member

Unfortunately it is expected. The route :splat* does not match /foo/bar.md, only the second one would. Since the idea is to rebuild a URL that would match correctly, this is the expected behavior.

It stands to reason that :splat* could just be wrong too. There's no option in the library today for "implicitly use / as the prefix", but there could be. And that might solve your issue. But I'd be inclined to suggest using the / prefix explicitly unless there's a good reason you can't.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants