Skip to content

Commit ae4742f

Browse files
Merge branch '2.8' into 3.0
* 2.8: [PropertyAccess] ->getValue() should be read-only [VarDumper] Fix dumping type hints for non-existing parent classes [Config] Fix XmlUtilsTest namespace [Console] [TableHelper] make it work with SymfonyStyle. Remove dead code [Routing] add query param if value is different from default Conflicts: src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php
2 parents 0013248 + faf78fa commit ae4742f

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

Generator/UrlGenerator.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,10 @@ protected function doGenerate($variables, $defaults, $requirements, $tokens, $pa
267267
}
268268

269269
// add a query string if needed
270-
$extra = array_diff_key($parameters, $variables, $defaults);
270+
$extra = array_udiff_assoc(array_diff_key($parameters, $variables), $defaults, function ($a, $b) {
271+
return $a == $b ? 0 : 1;
272+
});
273+
271274
if ($extra && $query = http_build_query($extra, '', '&')) {
272275
// "/" and "?" can be left decoded for better user experience, see
273276
// http://tools.ietf.org/html/rfc3986#section-3.4

Tests/Generator/UrlGeneratorTest.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,22 @@ public function testNullForOptionalParameterIsIgnored()
297297

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

302-
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', array('default' => 'foo')));
303-
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', array('default' => 'value')));
302+
$this->assertSame('/app.php/test?page=2', $this->getGenerator($routes)->generate('test', array('page' => 2)));
303+
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', array('page' => 1)));
304+
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', array('page' => '1')));
305+
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test'));
306+
}
307+
308+
public function testArrayQueryParamSameAsDefault()
309+
{
310+
$routes = $this->getRoutes('test', new Route('/test', array('array' => array('foo', 'bar'))));
311+
312+
$this->assertSame('/app.php/test?array%5B0%5D=bar&array%5B1%5D=foo', $this->getGenerator($routes)->generate('test', array('array' => array('bar', 'foo'))));
313+
$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'))));
314+
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', array('array' => array('foo', 'bar'))));
315+
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', array('array' => array(1 => 'bar', 0 => 'foo'))));
304316
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test'));
305317
}
306318

0 commit comments

Comments
 (0)