Skip to content

Commit 880210f

Browse files
[Routing] don't decode nor double-encode already encoded slashes when generating URLs
1 parent 8931b1d commit 880210f

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
5.3.0
5+
-----
6+
7+
* already encoded slashes are not decoded nor double-encoded anymore when generating URLs
8+
49
5.2.0
510
-----
611

Generator/UrlGenerator.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class UrlGenerator implements UrlGeneratorInterface, ConfigurableRequirementsInt
6666
// some webservers don't allow the slash in encoded form in the path for security reasons anyway
6767
// see http://stackoverflow.com/questions/4069002/http-400-if-2f-part-of-get-url-in-jboss
6868
'%2F' => '/',
69+
'%252F' => '%2F',
6970
// the following chars are general delimiters in the URI specification but have only special meaning in the authority component
7071
// so they can safely be used in the path in unencoded form
7172
'%40' => '@',

Tests/Generator/UrlGeneratorTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,12 @@ public function testEncodingOfRelativePathSegments()
467467
$this->assertSame('/app.php/a./.a/a../..a/...', $this->getGenerator($routes)->generate('test'));
468468
}
469469

470+
public function testEncodingOfSlashInPath()
471+
{
472+
$routes = $this->getRoutes('test', new Route('/dir/{path}/dir2', [], ['path' => '.+']));
473+
$this->assertSame('/app.php/dir/foo/bar%2Fbaz/dir2', $this->getGenerator($routes)->generate('test', ['path' => 'foo/bar%2Fbaz']));
474+
}
475+
470476
public function testAdjacentVariables()
471477
{
472478
$routes = $this->getRoutes('test', new Route('/{x}{y}{z}.{_format}', ['z' => 'default-z', '_format' => 'html'], ['y' => '\d+']));

0 commit comments

Comments
 (0)