8000 allow characters ? and / to remain unencoded in fragment, as per RFC · symfony/symfony@f97fb07 · GitHub
[go: up one dir, main page]

Skip to content

Commit f97fb07

Browse files
committed
allow characters ? and / to remain unencoded in fragment, as per RFC
1 parent 1915da8 commit f97fb07

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
@@ -291,7 +291,8 @@ protected function doGenerate($variables, $defaults, $requirements, $tokens, $pa
291291
}
292292

293293
if ($fragment) {
294-
$url .= '#'.rawurlencode($fragment);
294+
$validFragmentChars = array('%2F' => '/', '%3F' => '?');
295+
$url .= '#'.strtr(rawurlencode($fragment), $validFragmentChars);
295296
}
296297

297298
return $url;

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

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

660+
public function testFragmentsDoNotEscapeValidCharacters()
661+
{
662+
$routes = $this->getRoutes('test', new Route('/testing'));
663+
$url = $this->getGenerator($routes)->generate('test', array('_fragment' => '?/'), true);
664+
665+
$this->assertEquals('http://localhost/app.php/testing#?/', $url);
666+
}
667+
660668
protected function getGenerator(RouteCollection $routes, array $parameters = array(), $logger = null)
661669
{
662670
$context = new RequestContext('/app.php');

0 commit comments

Comments
 (0)
0