Skip to content
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

Fix remaining POSIX-only absolute path detection #10452

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Psalm/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -1315,7 +1315,7 @@ private static function fromXmlAndPaths(
}

// we need an absolute path for checks
if ($path[0] !== '/' && DIRECTORY_SEPARATOR === '/') {
if (Path::isRelative($path)) {
$prospective_path = $base_dir . DIRECTORY_SEPARATOR . $path;
} else {
$prospective_path = $path;
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Config/FileFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public static function loadFromArray(
foreach ($config['file'] as $file) {
$file_path = (string) ($file['name'] ?? '');

if ($file_path[0] === '/' && DIRECTORY_SEPARATOR === '/') {
if (Path::isAbsolute($file_path)) {
/** @var non-empty-string */
$prospective_file_path = $file_path;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Psalm\IssueBuffer;
use Psalm\Plugin\EventHandler\Event\AddRemoveTaintsEvent;
use Psalm\Type\TaintKind;
use Symfony\Component\Filesystem\Path;

use function constant;
use function defined;
Expand Down Expand Up @@ -93,13 +94,7 @@ public static function analyze(
$include_path = self::resolveIncludePath($path_to_file, dirname($statements_analyzer->getFilePath()));
$path_to_file = $include_path ?: $path_to_file;

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) {
if (Path::isRelative($path_to_file)) {
$path_to_file = $config->base_dir . DIRECTORY_SEPARATOR . $path_to_file;
}
} else {
Expand Down Expand Up @@ -285,13 +280,7 @@ public static function getPathTo(
string $file_name,
Config $config
): ?string {
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) {
if (Path::isRelative($file_name)) {
$file_name = $config->base_dir . DIRECTORY_SEPARATOR . $file_name;
}

Expand Down
10 changes: 2 additions & 8 deletions src/Psalm/Internal/PhpVisitor/Reflector/ExpressionScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
use Psalm\Storage\FileStorage;
use Psalm\Storage\FunctionLikeStorage;
use Psalm\Type;
use Symfony\Component\Filesystem\Path;

use function assert;
use function defined;
use function dirname;
use function explode;
use function in_array;
use function preg_match;
use function strpos;
use function strtolower;
use function substr;
Expand Down Expand Up @@ -316,13 +316,7 @@ public static function visitInclude(
$include_path = IncludeAnalyzer::resolveIncludePath($path_to_file, dirname($file_storage->file_path));
$path_to_file = $include_path ?: $path_to_file;

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) {
if (Path::isRelative($path_to_file)) {
$path_to_file = $config->base_dir . DIRECTORY_SEPARATOR . $path_to_file;
}
} else {
Expand Down