Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 01e0eb1

Browse files
committed
allow characters ? and / to remain unencoded in fragment, as per RFC
1 parent 3dda09c commit 01e0eb1

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,8 @@ protected function doGenerate($variables, $defaults, $requirements, $tokens, $pa
287287
}
288288

289289
if ($fragment) {
290-
$url .= '#'.rawurlencode($fragment);
290+
$validFragmentChars = array('%2F' => '/', '%3F' => '?');
291+
$url .= '#'.strtr(rawurlencode($fragment), $validFragmentChars);
291292
}
292293

293294
return $url;

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,14 @@ public function testFragmentsCanBeAppendedToUrls()
630630
$this->assertEquals('http://localhost/app.php/testing#frag%20ment', $url);
631631
}
632632

633+
public function testFragmentsDoNotEscapeValidCharacters()
634+
{
635+
$routes = $this->getRoutes('test', new Route('/testing'));
636+
$url = $this->getGenerator($routes)->generate('test', array('_fragment' => '?/'), true);
637+
638+
$this->assertEquals('http://localhost/app.php/testing#?/', $url);
639+
}
640+
633641
protected function getGenerator(RouteCollection $routes, array $parameters = array(), $logger = null)
634642
{
635643
$context = new RequestContext('/app.php');

0 commit comments

Comments
 (0)