
When an include is not surrounded by empty lines, its content is inlined on the same line as the adjacent content. That can lead to broken tags and other display issues. This PR fixes all such includes and introduces a validation step that forbids introducing the same problem again.
38 lines
690 B
Plaintext
38 lines
690 B
Plaintext
== How to fix it in Core PHP
|
|
|
|
=== Code examples
|
|
|
|
:code_impact: read
|
|
|
|
include::../../common/fix/code-rationale.adoc[]
|
|
|
|
==== Noncompliant code example
|
|
|
|
[source,php,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
$fileName = $_GET["filename"];
|
|
|
|
file_get_contents($fileName); // Noncompliant
|
|
----
|
|
|
|
==== Compliant solution
|
|
|
|
[source,php,diff-id=1,diff-type=compliant]
|
|
----
|
|
$fileName = $_GET["filename"];
|
|
$targetDirectory = "/path/to/target/directory/";
|
|
|
|
$path = realpath($targetDirectory . $fileName);
|
|
|
|
if (str_starts_with($path, $targetDirectory)) {
|
|
file_get_contents($path);
|
|
}
|
|
----
|
|
|
|
=== How does this work?
|
|
|
|
:canonicalization_function: `realPath`
|
|
|
|
include::../../common/fix/self-validation.adoc[]
|
|
|