Skip to content

Commit cf82d55

Browse files
committed
fix(core): Path::getRelativePath() will return correct path when $root is file.
(cherry picked from commit 9478b44)
1 parent c8baa09 commit cf82d55

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

packages/core/src/Utils/Path.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ public static function getPath(string $root, string $path): string {
1818
}
1919

2020
public static function getRelativePath(string $root, string $path): string {
21-
$path = static::isRelative($path)
22-
? static::join(static::getDirname($root), $path)
23-
: $path;
21+
$root = static::getDirname($root);
22+
$path = static::isRelative($path) ? static::join($root, $path) : $path;
2423
$path = SymfonyPath::makeRelative($path, $root);
2524
$path = static::normalize($path);
2625

packages/core/src/Utils/PathTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use LastDragon_ru\LaraASP\Core\Testing\Package\TestCase;
66
use PHPUnit\Framework\Attributes\CoversClass;
77

8+
use function basename;
89
use function dirname;
910
use function str_replace;
1011

@@ -25,6 +26,7 @@ public function testGetPath(): void {
2526
public function testGetRelativePath(): void {
2627
self::assertEquals('../to/file', Path::getRelativePath('/any/path', '/any/path/../to/file'));
2728
self::assertEquals('to/file', Path::getRelativePath('/absolute/path', 'to/./file'));
29+
self::assertEquals(basename(__FILE__), Path::getRelativePath(__FILE__, __FILE__));
2830
}
2931

3032
public function testJoin(): void {

0 commit comments

Comments
 (0)