Skip to content

Commit

Permalink
Fix prefix = false in connect()
Browse files Browse the repository at this point in the history
Connecting routes with a prefix = false created an un-matchable route.
Ignore falsey prefix values when setting up prefixes.

Fixes #2479
  • Loading branch information
markstory committed Jan 17, 2012
1 parent 3a3d89d commit c81fe62
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/Cake/Routing/Router.php
Expand Up @@ -233,7 +233,11 @@ public static function getNamedExpressions() {
public static function connect($route, $defaults = array(), $options = array()) {
foreach (self::$_prefixes as $prefix) {
if (isset($defaults[$prefix])) {
$defaults['prefix'] = $prefix;
if ($defaults[$prefix]) {
$defaults['prefix'] = $prefix;
} else {
unset($defaults[$prefix]);
}
break;
}
}
Expand Down
22 changes: 21 additions & 1 deletion lib/Cake/Test/Case/Routing/RouterTest.php
Expand Up @@ -1698,6 +1698,27 @@ public function testPrefixOverride() {
$this->assertEquals($expected, $result);
}

/**
* Test that setting a prefix to false is ignored, as its generally user error.
*
* @return void
*/
public function testPrefixFalseIgnored() {
Configure::write('Routing.prefixes', array('admin'));
Router::connect('/cache_css/*', array('admin' => false, 'controller' => 'asset_compress', 'action' => 'get'));

$url = Router::url(array('controller' => 'asset_compress', 'action' => 'get', 'test'));
$expected = '/cache_css/test';
$this->assertEquals($expected, $url);

$url = Router::url(array('admin' => false, 'controller' => 'asset_compress', 'action' => 'get', 'test'));
$expected = '/cache_css/test';
$this->assertEquals($expected, $url);

$url = Router::url(array('admin' => true, 'controller' => 'asset_compress', 'action' => 'get', 'test'));
$this->assertEquals('/admin/asset_compress/get/test', $url);
}

/**
* testRemoveBase method
*
Expand Down Expand Up @@ -2474,5 +2495,4 @@ public function testRouteRedirection() {
Router::parse('/not-a-match');
$this->assertEquals(Router::$routes[0]->response->header(), array());
}

}

0 comments on commit c81fe62

Please sign in to comment.