diff options
-rw-r--r-- | system/classes/route.php | 10 | ||||
-rw-r--r-- | tests/system/routeTest.php | 5 |
2 files changed, 11 insertions, 4 deletions
diff --git a/system/classes/route.php b/system/classes/route.php index c1b9457..244a0c7 100644 --- a/system/classes/route.php +++ b/system/classes/route.php @@ -80,13 +80,19 @@ class Route { $url = is_array($this->rule)?$this->rule[0]:$this->rule; - $replace = array('(' => '', ')' => ''); + $replace = array(); $params = array_merge($this->defaults, $params); foreach($params as $key => $value) $replace["<{$key}>"] = $value; - $url = str_replace(array_keys($replace), array_values($replace), $url); + $count = 1; + $chars='[^\(\)]*?'; + while($count>0) + $url = preg_replace("#\({$chars}<{$chars}>{$chars}\)#", '', $url, -1, $count); + + $url = str_replace(array('(', ')'), '', $url); + if ($absolute) $url = $protocol.'://'.$_SERVER['HTTP_HOST'].$url; diff --git a/tests/system/routeTest.php b/tests/system/routeTest.php index 58d0295..dc22931 100644 --- a/tests/system/routeTest.php +++ b/tests/system/routeTest.php @@ -113,11 +113,12 @@ class RoteTest extends PHPUnit_Framework_TestCase */ public function testUrl() { - Route::add('url', '/<controller>/<action>(/<id>)', array( + Route::add('url', '(/<controller>(/<action>(/<id>)))', array( 'controller' => 'home', 'action' => 'index' )); $route = Route::get('url'); - $this->assertEquals('/home/index/5', $route->url(array('id'=>5))); + $this->assertEquals('/home/index/5', $route-> url(array('id' => 5))); + $this->assertEquals('/home/index', $route->url()); } } |