[Routing] fixed URL generation when a non-optional variable is empty
This commit is contained in:
parent
8eb1dfc6a0
commit
4ed8d4f6b5
@ -108,7 +108,7 @@ class UrlGenerator implements UrlGeneratorInterface
|
|||||||
throw new \InvalidArgumentException(sprintf('Parameter "%s" for route "%s" must match "%s" ("%s" given).', $token[3], $name, $requirements[$token[3]], $tparams[$token[3]]));
|
throw new \InvalidArgumentException(sprintf('Parameter "%s" for route "%s" must match "%s" ("%s" given).', $token[3], $name, $requirements[$token[3]], $tparams[$token[3]]));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($tparams[$token[3]])) {
|
if ($tparams[$token[3]] || !$optional) {
|
||||||
// %2F is not valid in a URL, so we don't encode it (which is fine as the requirements explicitly allowed it)
|
// %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;
|
$url = $token[1].str_replace('%2F', '/', urlencode($tparams[$token[3]])).$url;
|
||||||
}
|
}
|
||||||
|
@ -74,6 +74,14 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals('/app.php/testing', $url);
|
$this->assertEquals('/app.php/testing', $url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testRelativeUrlWithNullParameterButNotOptional()
|
||||||
|
{
|
||||||
|
$routes = $this->getRoutes('test', new Route('/testing/{foo}/bar', array('foo' => null)));
|
||||||
|
$url = $this->getGenerator($routes)->generate('test', array(), false);
|
||||||
|
|
||||||
|
$this->assertEquals('/app.php/testing//bar', $url);
|
||||||
|
}
|
||||||
|
|
||||||
public function testRelativeUrlWithExtraParameters()
|
public function testRelativeUrlWithExtraParameters()
|
||||||
{
|
{
|
||||||
$routes = $this->getRoutes('test', new Route('/testing'));
|
$routes = $this->getRoutes('test', new Route('/testing'));
|
||||||
|
Reference in New Issue
Block a user