How to specify "?" for url-patterns as querystring and not "optional match" #414
-
|
Please give advice or recommendation for handling the "?" character, where it is found in a querystring such as "/the/path?the=query#the-hash". The context is this PR, where sources using older TypeError: Unexpected ? at index 9, expected end:
/the/path?the=query#the-hash;
visit https://git.new/pathToRegexpError for infoThe guide at pattern = pattern.replace(/\?/, '{.:optqspunct}');
// /the/path?the=query#the-hash
// -> /the/path{.:optqspunct}the=query#the-hashThe solution at the PR seems wrong, however, as the url is not using "?" to specify an "optional match" but it is just there as part of the url querystring. Thank you for this library and thank you in advance for any advice. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
It sounds like you aren't after the optional behavior (which is The reason it was required to be stricter was to avoid small changes becoming unexpected changes (e.g. |
Beta Was this translation helpful? Give feedback.
It sounds like you aren't after the optional behavior (which is
/:foo?) but rather a literal?. IIRC this became an error when the syntax become stricter in v6, and you need to escape with a backslash (e.g.\\?).The reason it was required to be stricter was to avoid small changes becoming unexpected changes (e.g.
/foo?and/:foo?mean much different things).