mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fix prefix = false in connect()
Connecting routes with a prefix = false created an un-matchable route. Ignore falsey prefix values when setting up prefixes. Fixes #2479
This commit is contained in:
parent
3a3d89d6d1
commit
c81fe6249d
2 changed files with 26 additions and 2 deletions
|
@ -233,7 +233,11 @@ class Router {
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1698,6 +1698,27 @@ class RouterTest extends CakeTestCase {
|
|||
$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
|
||||
*
|
||||
|
@ -2474,5 +2495,4 @@ class RouterTest extends CakeTestCase {
|
|||
Router::parse('/not-a-match');
|
||||
$this->assertEquals(Router::$routes[0]->response->header(), array());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue