Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Symfony/Component/Routing/Generator/UrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,10 @@ protected function doGenerate($variables, $defaults, $requirements, $tokens, $pa
}

// add a query string if needed
$extra = array_diff_key($parameters, $variables, $defaults);
$extra = array_udiff_assoc(array_diff_key($parameters, $variables), $defaults, function ($a, $b) {
return $a == $b ? 0 : 1;
});

if ($extra && $query = http_build_query($extra, '', '&')) {
$url .= '?'.$query;
}
Expand Down
18 changes: 15 additions & 3 deletions src/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,22 @@ public function testNullForOptionalParameterIsIgnored()

public function testQueryParamSameAsDefault()
{
$routes = $this->getRoutes('test', new Route('/test', array('default' => 'value')));
$routes = $this->getRoutes('test', new Route('/test', array('page' => 1)));

$this->assertSame('/app.php/test', $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?page=2', $this->getGenerator($routes)->generate('test', array('page' => 2)));
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', array('page' => 1)));
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', array('page' => '1')));
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test'));
}

public function testArrayQueryParamSameAsDefault()
{
$routes = $this->getRoutes('test', new Route('/test', array('array' => array('foo', 'bar'))));

$this->assertSame('/app.php/test?array%5B0%5D=bar&array%5B1%5D=foo', $this->getGenerator($routes)->generate('test', array('array' => array('bar', 'foo'))));
$this->assertSame('/app.php/test?array%5Ba%5D=foo&array%5Bb%5D=bar', $this->getGenerator($routes)->generate('test', array('array' => array('a' => 'foo', 'b' => 'bar'))));
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', array('array' => array('foo', 'bar'))));
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', array('array' => array(1 => 'bar', 0 => 'foo'))));
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test'));
}

Expand Down