Skip to content
Permalink
Browse files

Fix #1940 - allow proper evaluation of /a/b/../../

  • Loading branch information...
muglug committed Jul 12, 2019
1 parent 9ac78b5 commit 1208437b4c933b3efbb0a61ba062fafb57ecce41
Showing with 12 additions and 1 deletion.
  1. +1 −1 src/Psalm/Internal/Analyzer/Statements/Expression/IncludeAnalyzer.php
  2. +11 −0 tests/IncludeTest.php
@@ -335,7 +335,7 @@ public static function normalizeFilePath(string $path_to_file) : string
$reduce_pattern = '/\/[^\/]+\/\.\.\//';
while (preg_match($reduce_pattern, $path_to_file)) {
$path_to_file = preg_replace($reduce_pattern, DIRECTORY_SEPARATOR, $path_to_file);
$path_to_file = preg_replace($reduce_pattern, DIRECTORY_SEPARATOR, $path_to_file, 1);
}
$path_to_file = str_replace('/./', '/', $path_to_file);
@@ -558,6 +558,17 @@ function getEndpoints() : void {
getcwd() . DIRECTORY_SEPARATOR . 'file1.php',
],
],
'nestedParentFile' => [
'files' => [
getcwd() . DIRECTORY_SEPARATOR . 'a' . DIRECTORY_SEPARATOR . 'b' . DIRECTORY_SEPARATOR . 'c' . DIRECTORY_SEPARATOR . 'd' . DIRECTORY_SEPARATOR . 'script.php' => '<?php
require_once __DIR__ . "/../../../../e/begin.php";',
getcwd() . DIRECTORY_SEPARATOR . 'e' . DIRECTORY_SEPARATOR . 'begin.php' => '<?php
echo "hello";',
],
'files_to_check' => [
getcwd() . DIRECTORY_SEPARATOR . 'a' . DIRECTORY_SEPARATOR . 'b' . DIRECTORY_SEPARATOR . 'c' . DIRECTORY_SEPARATOR . 'd' . DIRECTORY_SEPARATOR . 'script.php',
],
],
];
}

0 comments on commit 1208437

Please sign in to comment.
You can’t perform that action at this time.