this.path RegExp shouldn't match word prefixes #34
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The RegExp used when this.path has optional parameters is currently matching word prefixes. For example, if a route's originalPath is
/person/:id?
, it is right now matching/persons
, but it shouldn't. This behavior is specially bad when a page is using routes like/person/:id?
and/persons/:type?
, in which case, if anyone types/persons
, the route that gets called is/person/:id?
, and not the correct one.Here's a simple proof of the problem:
And here's an example of the correct behavior (achieved by the proposed change):
Please review! I'd like to make this even better if posible 👍
I'm sorry that I didn't include any test for this. I did a quick look and I didn't find any specific test for the regexps. However, I'm willing to write one if necessary!
Thanks for the time and effort ✌️