Skip to content

Commit

Permalink
[Routing] fixed a bug when a default value is an integer
Browse files Browse the repository at this point in the history
A default value is always a string in the context of routing.
  • Loading branch information
fabpot committed Jul 17, 2011
1 parent 23ef605 commit a1d8c70
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Symfony/Component/Routing/Route.php
Expand Up @@ -161,7 +161,10 @@ public function getDefaults()
*/
public function setDefaults(array $defaults)
{
$this->defaults = $defaults;
$this->defaults = array();
foreach ($defaults as $name => $default) {
$this->defaults[(string) $name] = (string) $default;
}

return $this;
}
Expand Down Expand Up @@ -202,7 +205,7 @@ public function hasDefault($name)
*/
public function setDefault($name, $default)
{
$this->defaults[$name] = $default;
$this->defaults[(string) $name] = (string) $default;

return $this;
}
Expand Down
Expand Up @@ -191,6 +191,13 @@ public function testNoTrailingSlashForMultipleOptionalParameters()
$this->assertEquals('/app.php/category/foo', $this->getGenerator($routes)->generate('test', array('slug1' => 'foo')));
}

public function testWithAnIntegerAsADefaultValue()
{
$routes = $this->getRoutes('test', new Route('/{default}', array('default' => 0)));

$this->assertEquals('/app.php/foo', $this->getGenerator($routes)->generate('test', array('default' => 'foo')));
}

protected function getGenerator(RouteCollection $routes, array $parameters = array())
{
$context = new RequestContext('/app.php');
Expand Down

0 comments on commit a1d8c70

Please sign in to comment.