Fixing issue where named params equal to null/false would be part of the generated url.

This commit is contained in:
mark_story 2010-12-18 13:40:07 -05:00
parent 6ef8203d54
commit 8d404332a2
2 changed files with 12 additions and 1 deletions

View file

@ -267,7 +267,7 @@ class CakeRoute {
$named = $pass = $diff = array(); $named = $pass = $diff = array();
foreach ($url as $key => $value) { foreach ($url as $key => $value) {
// pull out named params so comparisons later on are faster. // pull out named params so comparisons later on are faster.
if ($key[0] === ':') { if ($key[0] === ':' && ($value !== false && $value !== null)) {
$named[substr($key, 1)] = $value; $named[substr($key, 1)] = $value;
unset($url[$key]); unset($url[$key]);
continue; continue;

View file

@ -338,6 +338,17 @@ class CakeRouteTestCase extends CakeTestCase {
$this->assertFalse($result); $this->assertFalse($result);
} }
/**
* test that named params with null/false are excluded
*
* @return void
*/
function testNamedParamsWithNullFalse() {
$route = new CakeRoute('/:controller/:action/*', array('plugin' => null));
$result = $route->match(array('controller' => 'posts', 'action' => 'index', ':page' => null, 'sort' => false));
$this->assertEquals('/posts/index/', $result);
}
/** /**
* test that match with patterns works. * test that match with patterns works.
* *