Skip to content

Commit 1421298

Browse files
committed
[Routing] query parameters: don't decode nor double-encode already encoded slashes when generating URLs
1 parent 1df76df commit 1421298

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

src/Symfony/Component/Routing/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ CHANGELOG
77
* Add `getMissingParameters` and `getRouteName` methods on `MissingMandatoryParametersException`
88
* Allow using UTF-8 parameter names
99
* Support the `attribute` type (alias of `annotation`) in annotation loaders
10+
* Already encoded slashes are not decoded nor double-encoded anymore when generating URLs (query parameters)
1011

1112
5.3
1213
---

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

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class UrlGenerator implements UrlGeneratorInterface, ConfigurableRequirementsInt
3030
private const QUERY_FRAGMENT_DECODED = [
3131
// RFC 3986 explicitly allows those in the query/fragment to reference other URIs unencoded
3232
'%2F' => '/',
33+
'%252F' => '%2F',
3334
'%3F' => '?',
3435
// reserved chars that have no special meaning for HTTP URIs in a query or fragment
3536
// this excludes esp. "&", "=" and also "+" because PHP would treat it as a space (form-encoded)

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

+7
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,13 @@ public function testEncodingOfSlashInPath()
527527
$this->assertSame('/app.php/dir/foo/bar%2Fbaz/dir2', $this->getGenerator($routes)->generate('test', ['path' => 'foo/bar%2Fbaz']));
528528
}
529529

530+
public function testEncodingOfSlashInQueryParameters()
531+
{
532+
$routes = $this->getRoutes('test', new Route('/get'));
533+
$this->assertSame('/app.php/get?query=foo/bar', $this->getGenerator($routes)->generate('test', ['query' => 'foo/bar']));
534+
$this->assertSame('/app.php/get?query=foo%2Fbar', $this->getGenerator($routes)->generate('test', ['query' => 'foo%2Fbar']));
535+
}
536+
530537
public function testAdjacentVariables()
531538
{
532539
$routes = $this->getRoutes('test', new Route('/{x}{y}{z}.{_format}', ['z' => 'default-z', '_format' => 'html'], ['y' => '\d+']));

0 commit comments

Comments
 (0)