diff --git a/src/Symfony/Component/Routing/Generator/UrlGenerator.php b/src/Symfony/Component/Routing/Generator/UrlGenerator.php index dc46c60fb98c7..355f31a8c5a71 100644 --- a/src/Symfony/Component/Routing/Generator/UrlGenerator.php +++ b/src/Symfony/Component/Routing/Generator/UrlGenerator.php @@ -258,6 +258,11 @@ protected function doGenerate($variables, $defaults, $requirements, $tokens, $pa // add a query string if needed $extra = array_diff_key($parameters, $variables, $defaults); + foreach($parameters as $key => $value) { + if (isset($defaults[$key]) && !array_key_exists($key, $variables) && $defaults[$key] !== $value) { + $extra[$key] = $value; + } + } if ($extra && $query = http_build_query($extra, '', '&')) { $url .= '?'.$query; } diff --git a/src/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php b/src/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php index d7b74f01e1bb3..5b31731a182c8 100644 --- a/src/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php +++ b/src/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php @@ -117,6 +117,27 @@ public function testAbsoluteUrlWithExtraParameters() $this->assertEquals('http://localhost/app.php/testing?foo=bar', $url); } + public function testAbsoluteUrlWithExtraParametersAndDefault() + { + $routes = $this->getRoutes('test', new Route('/testing', array('foo' => 'bell'))); + $url = $this->getGenerator($routes)->generate('test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_URL); + $this->assertEquals('http://localhost/app.php/testing?foo=bar', $url); + } + + public function testAbsoluteUrlWithExtraParametersAndArrayDefault() + { + $routes = $this->getRoutes('test', new Route('/testing', array('foo' => array('bell')))); + $url = $this->getGenerator($routes)->generate('test', array('foo' => array('bar')), UrlGeneratorInterface::ABSOLUTE_URL); + $this->assertEquals('http://localhost/app.php/testing?foo%5B0%5D=bar', $url); + } + + public function testAbsoluteUrlWithoutExtraParametersAndArrayDefault() + { + $routes = $this->getRoutes('test', new Route('/testing', array('foo' => array('bell')))); + $url = $this->getGenerator($routes)->generate('test', array('foo' => array('bell')), UrlGeneratorInterface::ABSOLUTE_URL); + $this->assertEquals('http://localhost/app.php/testing', $url); + } + public function testUrlWithNullExtraParameters() { $routes = $this->getRoutes('test', new Route('/testing')); @@ -293,7 +314,7 @@ public function testQueryParamSameAsDefault() { $routes = $this->getRoutes('test', new Route('/test', array('default' => 'value'))); - $this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', array('default' => 'foo'))); + $this->assertSame('/app.php/test?default=foo', $this->getGenerator($routes)->generate('test', array('default' => 'foo'))); $this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', array('default' => 'value'))); $this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test')); }