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

Using match with wildcard route breaks #212

Closed
ghost opened this issue Nov 29, 2019 · 2 comments
Closed

Using match with wildcard route breaks #212

ghost opened this issue Nov 29, 2019 · 2 comments

Comments

@ghost
Copy link

ghost commented Nov 29, 2019

Hello!

I want to use match to match a given hash (from our client hash router) to a predefined set of paths, e.g. we have a path #/user/:id and I want to have #/user/123 produce a match. In addition we have a catch-all route, which is #/* which should produce a match when I pass in #/:

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

match('#/*')('#/')

but it fails with

TypeError: Unexpected MODIFIER at 2, expected END
    at mustConsume (/home/runner/node_modules/path-to-regexp/dist/index.js:113:15)
    at parse (/home/runner/node_modules/path-to-regexp/dist/index.js:172:9)
    at stringToRegexp (/home/runner/node_modules/path-to-regexp/dist/index.js:329:27)
    at pathToRegexp (/home/runner/node_modules/path-to-regexp/dist/index.js:403:12)
    at match (/home/runner/node_modules/path-to-regexp/dist/index.js:248:14)
    at /home/runner/index.js:3:1
    at Script.runInContext (vm.js:133:20)
    at Object.<anonymous> (/run_dir/interp.js:156:20)
    at Module._compile (internal/modules/cjs/loader.js:778:30)

See this REPL: https://repl.it/repls/GenuineAssuredControlflowgraph

Is this a bug or is it not supported? Is there a workaround?

This occurs with v6 of your library, in previous version it seemed to be working.

Thanks for your help, I’m happy to share more information if needed!

@blakeembrey
Copy link
Member

blakeembrey commented Nov 29, 2019

@tfchristianost An asterisk like that hasn't worked since V1, a little over two years ago: https://github.com/pillarjs/path-to-regexp/blob/master/History.md#200--2017-08-23. You can check with the documentation in the README, there's a section that may help you: https://github.com/pillarjs/path-to-regexp#compatibility-with-express--4x. If you wanted a literal *, you'd want to escape it with \*.

@ghost
Copy link
Author

ghost commented Dec 2, 2019

Oh wow, I wonder how that worked before then 😅 Thanks for the reply, I’ll have a look into the linked section!

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

1 participant