Fixed issue with splats when used with named parameters.

pull/145/head
Mike Cao 11 years ago
parent 44eee92fdf
commit 88f4c1fb71

@ -1 +1 @@
1.2.2
1.2.3

@ -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

@ -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');
}
}

Loading…
Cancel
Save