Skip to content

Commit 6c1d168

Browse files
committed
Fixing a bug where having relativizePath failed if root was /src
1 parent 2ca7aea commit 6c1d168

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/FileManager.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ public function relativizePath($absolutePath): string
100100

101101
$absolutePath = $this->realPath($absolutePath);
102102

103-
$relativePath = ltrim(str_replace($this->rootDirectory, '', $absolutePath), '/');
103+
// str_replace but only the first occurrence
104+
$relativePath = ltrim(implode('', explode($this->rootDirectory, $absolutePath, 2)), '/');
104105
if (0 === strpos($relativePath, './')) {
105106
$relativePath = substr($relativePath, 2);
106107
}

tests/FileManagerTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ public function getRelativizePathTests()
5050
'D:\path\to\project\vendor\composer/../../src/Controller/TestController.php',
5151
'src/Controller/TestController.php',
5252
];
53+
54+
yield 'double_src' => [
55+
'/src',
56+
'/src/vendor/composer/../../src/Command/FooCommand.php',
57+
'src/Command/FooCommand.php',
58+
];
5359
}
5460

5561
/**

0 commit comments

Comments
 (0)