OSDN Git Service

Fixes the match route comparison just for left direction.
authorJack Makiyama <jack@phpbr.org>
Tue, 24 May 2016 05:40:03 +0000 (01:40 -0400)
committerJack Makiyama <jack@phpbr.org>
Tue, 24 May 2016 05:50:29 +0000 (01:50 -0400)
src/Router.php
tests/src/PHPRouterTest/RouterTest.php

index 03d87fe..8a4ddf0 100755 (executable)
@@ -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);
index 7263ff3..330b0e7 100644 (file)
@@ -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),
         );