From dc333c7efb6e064cf673bd6d3452f74ac26c8135 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Rodr=C3=ADguez?= Date: Tue, 30 May 2017 21:32:28 -0400 Subject: [PATCH] this.path RegExp shouldn't match prefixes of words MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 ✌️ --- src/route.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/route.js b/src/route.js index 8dee8cf..64c0cda 100644 --- a/src/route.js +++ b/src/route.js @@ -22,7 +22,7 @@ class Route { this.originalPath = this.path; //if there are optional parameters, replace the path with a regex expression - this.path = this.path.indexOf('?') === -1 ? this.path : this.path.replace(optionalRegex, "/?([^/]*)?$"); + this.path = this.path.indexOf('?') === -1 ? this.path : this.path.replace(optionalRegex, "(/([^/]*)?)?$"); this.rootPath = this.getRootPath(); //bind @@ -86,4 +86,4 @@ class Route { } } -export default Route; \ No newline at end of file +export default Route;