Skip to content

Commit

Permalink
Merge pull request #1115 from koushki/dev
Browse files Browse the repository at this point in the history
Bug in Router::match using scope
  • Loading branch information
nateabele committed Aug 30, 2014
2 parents 8e5f8a3 + 864638c commit 8e046ca
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
9 changes: 8 additions & 1 deletion net/http/Route.php
Expand Up @@ -336,6 +336,13 @@ protected function _matchMethod($options) {
protected function _matchKeys($options) {
$args = array('args' => 'args');

$scope = array();
if (!empty($options['scope'])) {
$scope = (array)$options['scope'] + array('params' => array());
$scope = array_flip($scope['params']);
}
unset($options['scope']);

if (array_intersect_key($options, $this->_match) != $this->_match) {
return false;
}
Expand All @@ -344,7 +351,7 @@ protected function _matchKeys($options) {
return false;
}
} else {
if (array_diff_key(array_diff_key($options, $this->_match), $this->_keys) !== array()) {
if (array_diff_key($options, $this->_match + $this->_keys + $scope)) {
return false;
}
}
Expand Down
4 changes: 2 additions & 2 deletions net/http/Router.php
Expand Up @@ -380,7 +380,7 @@ public static function match($url = array(), $context = null, array $options = a
$scope = $options['scope'];
if (isset(static::$_configurations[$scope])) {
foreach (static::$_configurations[$scope] as $route) {
if (!$match = $route->match($url, $context)) {
if (!$match = $route->match($url + array('scope' => static::attached($scope)), $context)) {
continue;
}
if ($route->canContinue()) {
Expand Down Expand Up @@ -456,7 +456,7 @@ protected static function _matchOptions(&$url, $context, $options) {

$base = isset($config['base']) ? '/' . $config['base'] : $defaults['base'];
$base = $base . ($config['prefix'] ? '/' . $config['prefix'] : '');
$config['base'] = $config['absolute'] ? '/' . trim($base, '/') : rtrim($base, '/');
$config['base'] = rtrim($config['absolute'] ? '/' . trim($base, '/') : $base, '/');
$defaults = $config + $defaults;
}
return $options + $defaults;
Expand Down
19 changes: 19 additions & 0 deletions tests/cases/net/http/RouterTest.php
Expand Up @@ -1900,6 +1900,25 @@ public function testLibraryBasedRoute() {
));
$this->assertEqual($expected, $result);
}

public function testMatchWithAbsoluteScope() {
Router::attach('app', array(
'absolute' => true,
'host' => '{:domain}',
));

Router::scope('app', function(){
Router::connect('/hello', 'Posts::index');
});

$request = new Request(array('url' => '/hello', 'base' => ''));
$result = Router::process($request);

$expected = 'http://' . $result->params['domain'] . '/hello';
$result = Router::match($result->params, $request);

$this->assertEqual($expected, $result);
}
}

?>

0 comments on commit 8e046ca

Please sign in to comment.