From 41b8118e7d2c0571a0407d6cee4e7e68597c0e54 Mon Sep 17 00:00:00 2001 From: Jack Makiyama Date: Tue, 24 May 2016 01:40:03 -0400 Subject: [PATCH] Fixes the match route comparison just for left direction. --- src/Router.php | 5 +++-- tests/src/PHPRouterTest/RouterTest.php | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Router.php b/src/Router.php index 03d87fe..8a4ddf0 100755 --- a/src/Router.php +++ b/src/Router.php @@ -112,8 +112,9 @@ class Router $requestUrl = str_replace($currentDir, '', $requestUrl); } - // check if request _url matches route regex. if not, return false. - if (!preg_match("@^" . $this->basePath . $routes->getRegex() . "*$@i", $requestUrl, $matches)) { + $route = rtrim($routes->getRegex(), '/'); + $pattern = "@^{$this->basePath}{$route}/?$@i"; + if (!preg_match($pattern, $requestUrl, $matches)) { continue; } $matchedText = array_shift($matches); diff --git a/tests/src/PHPRouterTest/RouterTest.php b/tests/src/PHPRouterTest/RouterTest.php index 7263ff3..330b0e7 100644 --- a/tests/src/PHPRouterTest/RouterTest.php +++ b/tests/src/PHPRouterTest/RouterTest.php @@ -194,6 +194,7 @@ class RouterTest extends PHPUnit_Framework_TestCase array($router, '/', true), array($router, '/aaa', false), array($router, '/users', true), + array($router, '/usersssss', false), array($router, '/user/1', true), array($router, '/user/%E3%81%82', true), ); @@ -217,6 +218,7 @@ class RouterTest extends PHPUnit_Framework_TestCase array($router, '/api', true), array($router, '/api/aaa', false), array($router, '/api/users', true), + array($router, '/api/userssss', false), array($router, '/api/user/1', true), array($router, '/api/user/%E3%81%82', true), ); -- 2.11.0