Skip to content

Commit

Permalink
Fix additional places where base_dir was broken due to missing separator
Browse files Browse the repository at this point in the history
Improves upon vimeo#10542 and vimeo#10628
  • Loading branch information
kkmuffme committed Feb 1, 2024
1 parent 0082207 commit 305a0d4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/Psalm/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -1445,7 +1445,7 @@ private static function fromXmlAndPaths(
if (!$file_path) {
throw new ConfigException(
'Cannot resolve stubfile path '
. rtrim($config->base_dir, DIRECTORY_SEPARATOR)
. $config->base_dir
. DIRECTORY_SEPARATOR
. $stub_file['name'],
);
Expand Down Expand Up @@ -1582,11 +1582,11 @@ public function safeSetCustomErrorLevel(string $issue_key, string $error_level):
private function loadFileExtensions(SimpleXMLElement $extensions): void
{
foreach ($extensions as $extension) {
$extension_name = preg_replace('/^\.?/', '', (string)$extension['name'], 1);
$extension_name = preg_replace('/^\.?/', '', (string) $extension['name'], 1);
$this->file_extensions[] = $extension_name;

if (isset($extension['scanner'])) {
$path = $this->base_dir . (string)$extension['scanner'];
$path = $this->base_dir . DIRECTORY_SEPARATOR . (string) $extension['scanner'];

if (!file_exists($path)) {
throw new ConfigException('Error parsing config: cannot find file ' . $path);
Expand All @@ -1596,7 +1596,7 @@ private function loadFileExtensions(SimpleXMLElement $extensions): void
}

if (isset($extension['checker'])) {
$path = $this->base_dir . (string)$extension['checker'];
$path = $this->base_dir . DIRECTORY_SEPARATOR . (string) $extension['checker'];

if (!file_exists($path)) {
throw new ConfigException('Error parsing config: cannot find file ' . $path);
Expand Down Expand Up @@ -1817,7 +1817,7 @@ private function getPluginClassForPath(Codebase $codebase, string $path, string
public function shortenFileName(string $to): string
{
if (!is_file($to)) {
return preg_replace('/^' . preg_quote($this->base_dir, '/') . '/', '', $to, 1);
return preg_replace('/^' . preg_quote($this->base_dir . DIRECTORY_SEPARATOR, '/') . '?/', '', $to, 1);
}

$from = $this->base_dir;
Expand Down
2 changes: 1 addition & 1 deletion tests/TestConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct()
$this->level = 1;
$this->cache_directory = null;

$this->base_dir = getcwd() . DIRECTORY_SEPARATOR;
$this->base_dir = getcwd();

if (!self::$cached_project_files) {
self::$cached_project_files = ProjectFileFilter::loadFromXMLElement(
Expand Down

0 comments on commit 305a0d4

Please sign in to comment.