From eaac18be6fa1b3d7d25f32aa37d40c9de46f12aa Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 5 Jan 2021 21:33:59 +0100 Subject: [PATCH] [Routing] don't decode nor double-encode already encoded slashes when generating URLs --- src/Symfony/Component/Routing/CHANGELOG.md | 5 +++++ src/Symfony/Component/Routing/Generator/UrlGenerator.php | 1 + .../Component/Routing/Tests/Generator/UrlGeneratorTest.php | 6 ++++++ 3 files changed, 12 insertions(+) diff --git a/src/Symfony/Component/Routing/CHANGELOG.md b/src/Symfony/Component/Routing/CHANGELOG.md index 1d6f133ac1e0d..840df13441909 100644 --- a/src/Symfony/Component/Routing/CHANGELOG.md +++ b/src/Symfony/Component/Routing/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +5.3.0 +----- + + * already encoded slashes are not decoded nor double-encoded anymore when generating URLs + 5.2.0 ----- diff --git a/src/Symfony/Component/Routing/Generator/UrlGenerator.php b/src/Symfony/Component/Routing/Generator/UrlGenerator.php index b2768f7f533ab..8d26b26bd1e42 100644 --- a/src/Symfony/Component/Routing/Generator/UrlGenerator.php +++ b/src/Symfony/Component/Routing/Generator/UrlGenerator.php @@ -66,6 +66,7 @@ class UrlGenerator implements UrlGeneratorInterface, ConfigurableRequirementsInt // some webservers don't allow the slash in encoded form in the path for security reasons anyway // see http://stackoverflow.com/questions/4069002/http-400-if-2f-part-of-get-url-in-jboss '%2F' => '/', + '%252F' => '%2F', // the following chars are general delimiters in the URI specification but have only special meaning in the authority component // so they can safely be used in the path in unencoded form '%40' => '@', diff --git a/src/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php b/src/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php index cc5d894cfa688..94ca67534e6e9 100644 --- a/src/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php +++ b/src/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php @@ -467,6 +467,12 @@ public function testEncodingOfRelativePathSegments() $this->assertSame('/app.php/a./.a/a../..a/...', $this->getGenerator($routes)->generate('test')); } + public function testEncodingOfSlashInPath() + { + $routes = $this->getRoutes('test', new Route('/dir/{path}/dir2', [], ['path' => '.+'])); + $this->assertSame('/app.php/dir/foo/bar%2Fbaz/dir2', $this->getGenerator($routes)->generate('test', ['path' => 'foo/bar%2Fbaz'])); + } + public function testAdjacentVariables() { $routes = $this->getRoutes('test', new Route('/{x}{y}{z}.{_format}', ['z' => 'default-z', '_format' => 'html'], ['y' => '\d+']));