Regex in params extract extra characters with any capturing groups
spsquared opened this issue · 1 comments
spsquared commented
Reproduction
https://codesandbox.io/p/sandbox/vue-router-params-regex-bug-kdcvvs
Steps to reproduce the bug
- Create a router with a route that contains any regexp with capturing groups within it (like
(.)
) - Error as the regexp extracts the parenthesis from the route syntax
Expected behavior
The router extracts the regexp from inside the parenthesis and uses (.)
as its regexp.
Actual behavior
An error occurs as the syntax is included as part of the extracted regexp.
Additional information
(.)
is a fairly dumb expression but (a[abc])+
also breaks it.
posva commented
the ()
is already a regex group and the )
marks the end. Therefore you need to escape the closing )
: https://paths.esm.dev/?p=AAMsIPQgYAEL9lNgQAECUgPgDIFoDiiAwA5sbTACwBgAXQR0GqDkngCA&t=/abacac#. Note in JS strings, you need to escape the \
too