Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getBasePath() returns incorrect value for bare stream wrapper path #65

Open
wants to merge 2 commits into
base: 4.8.x
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions src/Glob.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,11 @@ public static function getBasePath($glob, $flags = 0)
return substr($staticPrefix, 0, $pos + 1);
}

// If the prefix is a no-path custom stream, that's a valid base path.
if ($pos - 2 === strrpos($staticPrefix, '://')) {
return $staticPrefix;
}

return substr($staticPrefix, 0, $pos);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Path.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static function isAbsolute(string $path): bool
}

// UNIX root "/" or "\" (Windows style)
if ('/' === $path[0] || '\\' === $path[0]) {
if ($path === '' || '/' === $path[0] || '\\' === $path[0]) {
return true;
}

Expand Down
8 changes: 7 additions & 1 deletion tests/GlobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ public function testGetBasePath($glob, $basePath, $flags = 0)
}

/**
* @dataProvider provideBasePaths
* @dataProvider provideBasePathsStream
*/
public function testGetBasePathStream($glob, $basePath)
{
Expand All @@ -793,6 +793,12 @@ public function provideBasePaths()
);
}

public function provideBasePathsStream()
{
yield from $this->provideBasePaths();
yield ['', ''];
}

public function testGetBasePathFailsIfNotAbsolute()
{
$this->expectException(\InvalidArgumentException::class);
Expand Down
Loading