Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [Unreleased]

### Fixed

- Some relative paths were parsed as absolute ones

## 5.2.0 - 2026-03-17

### Added
Expand Down
8 changes: 8 additions & 0 deletions src/Path.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ final public static function of(string $value): self
return new RelativePath($value);
}

// For some paths the parsing removes chars leading to the parsing
// thinking the path is absolute when the specified one is relative.
// But since we don't use the parsed string, to avoid using encoded
// strings, then the relative path is returned as an absolute one.
if ($value[0] !== '/') {
return new RelativePath($value);
}

return new AbsolutePath($value);
}

Expand Down
21 changes: 20 additions & 1 deletion tests/PathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@
AbsolutePath,
RelativePath,
};
use Innmind\BlackBox\PHPUnit\Framework\TestCase;
use Fixtures\Innmind\Url\Path as FPath;
use Innmind\BlackBox\{
PHPUnit\BlackBox,
PHPUnit\Framework\TestCase,
};
use PHPUnit\Framework\Attributes\DataProvider;

class PathTest extends TestCase
{
use BlackBox;

public function testInterface()
{
$p = Path::of('/foo/bar/');
Expand Down Expand Up @@ -79,6 +85,19 @@ public function testNamedConstructorsReturnsAppropriateSubType()
$this->assertInstanceOf(RelativePath::class, Path::of('../somewhere'));
}

public function testAbsolutePathsAlwaysStartWithASlash(): BlackBox\Proof
{
return $this
->forAll(FPath::any())
->prove(function($path) {
if ($path->absolute()) {
$this->assertStringStartsWith('/', $path->toString());
} else {
$this->assertStringStartsNotWith('/', $path->toString());
}
});
}

public static function resolutions(): array
{
return [
Expand Down
Loading