From 0ea053bda16bf0143c24c9c66614ea9b8fc8be8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Kowalewski?= Date: Thu, 12 Apr 2018 21:15:57 +0200 Subject: [PATCH] Fix detecting relative paths on windows Fixes vimeo/psalm#655 --- .../Statements/Expression/IncludeChecker.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Psalm/Checker/Statements/Expression/IncludeChecker.php b/src/Psalm/Checker/Statements/Expression/IncludeChecker.php index 7803d3a33..29c079f68 100644 --- a/src/Psalm/Checker/Statements/Expression/IncludeChecker.php +++ b/src/Psalm/Checker/Statements/Expression/IncludeChecker.php @@ -41,7 +41,13 @@ class IncludeChecker $include_path = self::resolveIncludePath($path_to_file, dirname($statements_checker->getCheckedFileName())); $path_to_file = $include_path ? $include_path : $path_to_file; - if ($path_to_file[0] !== DIRECTORY_SEPARATOR) { + if (DIRECTORY_SEPARATOR === '/') { + $is_path_relative = $path_to_file[0] !== DIRECTORY_SEPARATOR; + } else { + $is_path_relative = !preg_match('~^[A-Z]:\\\\~i', $path_to_file); + } + + if ($is_path_relative) { $path_to_file = getcwd() . DIRECTORY_SEPARATOR . $path_to_file; } } else { @@ -57,7 +63,7 @@ class IncludeChecker } // if the file is already included, we can't check much more - if (in_array($path_to_file, get_included_files(), true)) { + if (in_array(realpath($path_to_file), get_included_files(), true)) { return null; } @@ -119,7 +125,13 @@ class IncludeChecker */ public static function getPathTo(PhpParser\Node\Expr $stmt, $file_name) { - if ($file_name[0] !== DIRECTORY_SEPARATOR) { + if (DIRECTORY_SEPARATOR === '/') { + $is_path_relative = $file_name[0] !== DIRECTORY_SEPARATOR; + } else { + $is_path_relative = !preg_match('~^[A-Z]:\\\\~i', $file_name); + } + + if ($is_path_relative) { $file_name = getcwd() . DIRECTORY_SEPARATOR . $file_name; }