Skip to content

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

Open
sadasant wants to merge 1 commit into
kitze:masterfrom
smartprocure:patch-1
Open

this.path RegExp shouldn't match word prefixes#34
sadasant wants to merge 1 commit into
kitze:masterfrom
smartprocure:patch-1

Conversation

@sadasant

@sadasant sadasant commented May 31, 2017

Copy link
Copy Markdown

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.

1 participant