8000 bug #20001 [Routing] Fixed route generation with fragment defined as … · enumag/symfony@5832c9d · GitHub
[go: up one dir, main page]

Skip to content

Commit 5832c9d

Browse files
committed
bug symfony#20001 [Routing] Fixed route generation with fragment defined as defaults (akovalyov)
This PR was merged into the 3.2-dev branch. Discussion ---------- [Routing] Fixed route generation with fragment defined as defaults | Q | A | ------------- | --- | Branch? | "master" | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | License | MIT As stated in https://symfony.com/blog/new-in-symfony-3-2-routing-improvements, it should support `_fragment` option as part of `_defaults` of route definition. Commits ------- 3c36596 [Routing] Fixed route generation with fragment defined as defaults
2 parents 8148725 + 3c36596 commit 5832c9d

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/Symfony/Component/Routing/Generator/UrlGenerator.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,15 @@ protected function doGenerate($variables, $defaults, $requirements, $tokens, $pa
263263
});
264264

265265
// extract fragment
266-
$fragment = isset($extra['_fragment']) ? $extra['_fragment'] : '';
267-
unset($extra['_fragment']);
266+
$fragment = '';
267+
if (isset($defaults['_fragment'])) {
268+
$fragment = $defaults['_fragment'];
269+
}
270+
271+
if (isset($extra['_fragment'])) {
272+
$fragment = $extra['_fragment'];
273+
unset($extra['_fragment']);
274+
}
268275

269276
if ($extra && $query = http_build_query($extra, '', '&', PHP_QUERY_RFC3986)) {
270277
// "/" and "?" can be left decoded for better user experience, see

src/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,14 @@ public function testFragmentsDoNotEscapeValidCharacters()
662662
$this->assertEquals('/app.php/testing#?/', $url);
663663
}
664664

665+
public function testFragmentsCanBeDefinedAsDefaults()
666+
{
667+
$routes = $this->getRoutes('test', new Route('/testing', array('_fragment' => 'fragment')));
668+
$url = $this->getGenerator($routes)->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_PATH);
669+
670+
$this->assertEquals('/app.php/testing#fragment', $url);
671+
}
672+
665673
protected function getGenerator(RouteCollection $routes, array $parameters = array(), $logger = null)
666674
{
667675
$context = new RequestContext('/app.php');

0 commit comments

Comments
 (0)
0