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

this.path RegExp shouldn't match word prefixes #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

this.path RegExp shouldn't match word prefixes #34

wants to merge 1 commit into from

Conversation

sadasant
Copy link

@sadasant sadasant commented May 31, 2017

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:

> (new RegExp('/request/?([^/]*)?$')).test('/request')
true
> (new RegExp('/request/?([^/]*)?$')).test('/requests')
true

And here's an example of the correct behavior (achieved by the proposed change):

> (new RegExp('/request(/([^/]*)?)?$')).test('/request')
true
> (new RegExp('/request(/([^/]*)?)?$')).test('/requests')
false

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 ✌️

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.

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 ✌️
@sadasant sadasant changed the title this.path RegExp shouldn't match prefixes of words this.path RegExp shouldn't match word prefixes Jun 9, 2017
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

Successfully merging this pull request may close these issues.

None yet

1 participant