diff --git a/VERSION b/VERSION index 23aa839..0495c4a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.2.2 +1.2.3 diff --git a/flight/net/Route.php b/flight/net/Route.php index de063a2..af04a01 100644 --- a/flight/net/Route.php +++ b/flight/net/Route.php @@ -82,7 +82,20 @@ class Route { $ids = array(); $char = substr($this->pattern, -1); - $this->splat = substr($url, strpos($this->pattern, '*')); + // Get splat + if ($char === '*') { + $n = 0; + $len = strlen($url); + $count = substr_count($this->pattern, '/'); + + for ($i = 0; $i < $len; $i++) { + if ($url[$i] == '/') $n++; + if ($n == $count) break; + } + + $this->splat = substr($url, $i+1); + } + $this->pattern = str_replace(array(')','*'), array(')?','.*?'), $this->pattern); // Build the regex for matching diff --git a/tests/RouterTest.php b/tests/RouterTest.php index 2f2f153..a57cbe9 100644 --- a/tests/RouterTest.php +++ b/tests/RouterTest.php @@ -176,4 +176,17 @@ class RouterTest extends PHPUnit_Framework_TestCase $this->check('456/def/xyz'); } + + // Test splat with named parameters + function testSplatNamedPlusWildcard(){ + $this->router->map('/account/@name/*', function($name, $route){ + echo $route->splat; + $this->assertEquals('abc', $name); + }, + true); + + $this->request->url = '/account/abc/456/def/xyz'; + + $this->check('456/def/xyz'); + } }