Skip to content

Commit

Permalink
bug #20001 [Routing] Fixed route generation with fragment defined as …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
fabpot committed Sep 21, 2016
2 parents 8148725 + 3c36596 commit 5832c9d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/Symfony/Component/Routing/Generator/UrlGenerator.php
Expand Up @@ -263,8 +263,15 @@ protected function doGenerate($variables, $defaults, $requirements, $tokens, $pa
});

// extract fragment
$fragment = isset($extra['_fragment']) ? $extra['_fragment'] : '';
unset($extra['_fragment']);
$fragment = '';
if (isset($defaults['_fragment'])) {
$fragment = $defaults['_fragment'];
}

if (isset($extra['_fragment'])) {
$fragment = $extra['_fragment'];
unset($extra['_fragment']);
}

if ($extra && $query = http_build_query($extra, '', '&', PHP_QUERY_RFC3986)) {
// "/" and "?" can be left decoded for better user experience, see
Expand Down
Expand Up @@ -662,6 +662,14 @@ public function testFragmentsDoNotEscapeValidCharacters()
$this->assertEquals('/app.php/testing#?/', $url);
}

public function testFragmentsCanBeDefinedAsDefaults()
{
$routes = $this->getRoutes('test', new Route('/testing', array('_fragment' => 'fragment')));
$url = $this->getGenerator($routes)->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_PATH);

$this->assertEquals('/app.php/testing#fragment', $url);
}

protected function getGenerator(RouteCollection $routes, array $parameters = array(), $logger = null)
{
$context = new RequestContext('/app.php');
Expand Down

0 comments on commit 5832c9d

Please sign in to comment.