2023-03-07 17:16:47 +01:00
|
|
|
== How to fix it in Symfony
|
|
|
|
|
|
|
|
=== Code examples
|
2022-10-24 11:45:06 +02:00
|
|
|
|
|
|
|
include::../../common/fix/code-rationale.adoc[]
|
|
|
|
|
|
|
|
==== Noncompliant code example
|
|
|
|
|
|
|
|
[source,php,diff-id=1,diff-type=noncompliant]
|
|
|
|
----
|
|
|
|
function route(): RedirectResponse {
|
|
|
|
$route = $request->get('route');
|
|
|
|
return $this->redirect($route); // Noncompliant
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
|
|
|
==== Compliant solution
|
|
|
|
|
|
|
|
[source,php,diff-id=1,diff-type=compliant]
|
|
|
|
----
|
|
|
|
function route(): RedirectResponse {
|
|
|
|
$route = $request->get('route');
|
|
|
|
return $this->redirectToRoute($route, [], 301);
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
|
|
|
include::../../common/fix/how-does-this-work.adoc[]
|
|
|
|
|
|
|
|
=== Pitfalls
|
|
|
|
|
|
|
|
include::../../common/pitfalls/starts-with.adoc[]
|