From 57f126e9ea3ce38266cb5bffd6c2b56f7d1676cc Mon Sep 17 00:00:00 2001 From: Gordon Franke Date: Tue, 29 Jan 2013 09:24:38 +0100 Subject: [PATCH] remove route query param when it is the same as default --- src/Symfony/Component/Routing/Generator/UrlGenerator.php | 1 + .../Component/Routing/Tests/Generator/UrlGeneratorTest.php | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Routing/Generator/UrlGenerator.php b/src/Symfony/Component/Routing/Generator/UrlGenerator.php index 2a6328ad3f8f6..25c915c214ac1 100644 --- a/src/Symfony/Component/Routing/Generator/UrlGenerator.php +++ b/src/Symfony/Component/Routing/Generator/UrlGenerator.php @@ -262,6 +262,7 @@ protected function doGenerate($variables, $defaults, $requirements, $tokens, $pa // add a query string if needed $extra = array_diff_key($parameters, $variables); + $extra = array_diff_assoc($extra, $defaults); 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 0728503b0632c..363d7ffeb2e81 100644 --- a/src/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php +++ b/src/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php @@ -291,7 +291,7 @@ public function testQueryParamSameAsDefault() $routes = $this->getRoutes('test', new Route('/test', array('default' => 'value'))); $this->assertSame('/app.php/test?default=foo', $this->getGenerator($routes)->generate('test', array('default' => 'foo'))); - $this->assertSame('/app.php/test?default=value', $this->getGenerator($routes)->generate('test', array('default' => 'value'))); + $this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', array('default' => 'value'))); $this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test')); } @@ -347,6 +347,7 @@ public function testOptionalVariableWithNoRealSeparator() $generator = $this->getGenerator($routes); $this->assertSame('/app.php/get', $generator->generate('test')); + $this->assertSame('/app.php/get', $generator->generate('test'), array('what' => 'All')); $this->assertSame('/app.php/getSites', $generator->generate('test', array('what' => 'Sites'))); }