diff --git a/CHANGELOG.md b/CHANGELOG.md index c2ecbb5..54388a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Fixed - Some relative paths were parsed as absolute ones +- Resolving a relative path from a root path returned an invalid path (as it started with 2 `/`) ## 5.2.0 - 2026-03-17 diff --git a/src/Path.php b/src/Path.php index 66975e3..e372e17 100644 --- a/src/Path.php +++ b/src/Path.php @@ -121,6 +121,10 @@ final public function resolve(self $path): self $parent = \dirname($this->toString()); + if ($parent === '/') { + return self::of('/'.$path->toString()); + } + return self::of($parent.'/'.$path->toString()); } diff --git a/tests/PathTest.php b/tests/PathTest.php index 02e4347..01551a2 100644 --- a/tests/PathTest.php +++ b/tests/PathTest.php @@ -98,6 +98,18 @@ public function testAbsolutePathsAlwaysStartWithASlash(): BlackBox\Proof }); } + public function testResolveAbsolutility(): BlackBox\Proof + { + return $this + ->forAll(FPath::any(), FPath::any()) + ->prove(function($a, $b) { + $this->assertSame( + $a->absolute() || $b->absolute(), + $a->resolve($b)->absolute(), + ); + }); + } + public static function resolutions(): array { return [ @@ -126,6 +138,11 @@ public static function resolutions(): array 'some/source', 'some/target', ], + 'relative to the root' => [ + '/target', + '/source', + 'target', + ], ]; } }