diff --git a/src/Symfony/Component/Routing/Generator/UrlGenerator.php b/src/Symfony/Component/Routing/Generator/UrlGenerator.php index 3e445a8245..3f959cdc98 100644 --- a/src/Symfony/Component/Routing/Generator/UrlGenerator.php +++ b/src/Symfony/Component/Routing/Generator/UrlGenerator.php @@ -110,7 +110,7 @@ class UrlGenerator implements UrlGeneratorInterface 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; } diff --git a/tests/Symfony/Tests/Component/Routing/Generator/UrlGeneratorTest.php b/tests/Symfony/Tests/Component/Routing/Generator/UrlGeneratorTest.php index 6434459362..5d52d286f5 100644 --- a/tests/Symfony/Tests/Component/Routing/Generator/UrlGeneratorTest.php +++ b/tests/Symfony/Tests/Component/Routing/Generator/UrlGeneratorTest.php @@ -82,6 +82,14 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase $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'));