Skip to content

Commit

Permalink
[Routing] fixed URL generation when an optional variable value is 0
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Apr 26, 2011
1 parent 035afc1 commit fefee0d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Symfony/Component/Routing/Generator/UrlGenerator.php
Expand Up @@ -110,7 +110,7 @@ protected function doGenerate($variables, $defaults, $requirements, $tokens, $pa
throw new \InvalidArgumentException(sprintf('Parameter "%s" for route "%s" must match "%s" ("%s" given).', $token[3], $name, $token[2], $tparams[$token[3]]));
}

if ($tparams[$token[3]] || !$optional) {
if (!in_array($tparams[$token[3]], array(null, '', false), true) || !$optional) {
// %2F is not valid in a URL, so we don't encode it (which is fine as the requirements explicitly allowed it)
$url = $token[1].str_replace('%2F', '/', urlencode($tparams[$token[3]])).$url;
}
Expand Down
Expand Up @@ -82,6 +82,14 @@ public function testRelativeUrlWithNullParameterButNotOptional()
$this->assertEquals('/app.php/testing//bar', $url);
}

public function testRelativeUrlWithOptionalZeroParameter()
{
$routes = $this->getRoutes('test', new Route('/testing/{page}'));
$url = $this->getGenerator($routes)->generate('test', array('page' => 0), false);

$this->assertEquals('/app.php/testing/0', $url);
}

public function testRelativeUrlWithExtraParameters()
{
$routes = $this->getRoutes('test', new Route('/testing'));
Expand Down

0 comments on commit fefee0d

Please sign in to comment.