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

Skip to content

[Routing] Throw exception for non-array _query parameter #60863

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 8.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions UPGRADE-8.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,11 @@ PropertyInfo
}
```

Routing
-------

* Providing a non-array `_query` parameter to `UrlGenerator` causes an `InvalidParameterException`

Security
--------

Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/Routing/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

8.0
---

* Providing a non-array `_query` parameter to `UrlGenerator` causes an `InvalidParameterException`

7.4
---

Expand Down
3 changes: 1 addition & 2 deletions src/Symfony/Component/Routing/Generator/UrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ protected function doGenerate(array $variables, array $defaults, array $requirem
$queryParameters = $parameters['_query'];
unset($parameters['_query']);
} else {
trigger_deprecation('symfony/routing', '7.4', 'Parameter "_query" is reserved for passing an array of query parameters. Passing a scalar value is deprecated and will throw an exception in Symfony 8.0.');
// throw new InvalidParameterException('Parameter "_query" must be an array of query parameters.');
throw new InvalidParameterException('Parameter "_query" must be an array of query parameters.');
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1109,23 +1109,16 @@ public function testQueryParameterCannotSubstituteRouteParameter()
]);
}

/**
* @group legacy
*/
public function testQueryParametersWithScalarValue()
{
$routes = $this->getRoutes('user', new Route('/user/{id}'));

$this->expectUserDeprecationMessage(
'Since symfony/routing 7.4: Parameter "_query" is reserved for passing an array of query parameters. ' .
'Passing a scalar value is deprecated and will throw an exception in Symfony 8.0.',
);
$this->expectException(InvalidParameterException::class);

$url = $this->getGenerator($routes)->generate('user', [
$this->getGenerator($routes)->generate('user', [
'id' => '123',
'_query' => 'foo',
]);
$this->assertSame('/app.php/user/123?_query=foo', $url);
}

protected function getGenerator(RouteCollection $routes, array $parameters = [], $logger = null, ?string $defaultLocale = null)
Expand Down
Loading