From e8b5fada2c9e83ffd8c822fa0c113aaf8ec22baf Mon Sep 17 00:00:00 2001 From: Larry Garfield Date: Tue, 13 Aug 2024 16:26:18 -0500 Subject: [PATCH 1/2] Add test for empty path. --- tests/GlobTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/GlobTest.php b/tests/GlobTest.php index 07eb1d6..6545c2a 100644 --- a/tests/GlobTest.php +++ b/tests/GlobTest.php @@ -790,6 +790,7 @@ public function provideBasePaths() array('/foo/baz\\*/bar', '/foo/baz*'), array('/foo/baz\\\\*/bar', '/foo'), array('/foo/baz\\\\\\*/bar', '/foo/baz\\*'), + array('', ''), ); } From b7b5b9aba00d9be4849f3ef0df41d2f72998ca75 Mon Sep 17 00:00:00 2001 From: Larry Garfield Date: Wed, 14 Aug 2024 09:52:59 -0500 Subject: [PATCH 2/2] Allow for a no-path custom stream to be treated as a valid base path. --- src/Glob.php | 5 +++++ src/Path.php | 2 +- tests/GlobTest.php | 9 +++++++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Glob.php b/src/Glob.php index f1fa126..019d2bf 100644 --- a/src/Glob.php +++ b/src/Glob.php @@ -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); } diff --git a/src/Path.php b/src/Path.php index faead48..073f2c6 100644 --- a/src/Path.php +++ b/src/Path.php @@ -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; } diff --git a/tests/GlobTest.php b/tests/GlobTest.php index 6545c2a..8708d64 100644 --- a/tests/GlobTest.php +++ b/tests/GlobTest.php @@ -769,7 +769,7 @@ public function testGetBasePath($glob, $basePath, $flags = 0) } /** - * @dataProvider provideBasePaths + * @dataProvider provideBasePathsStream */ public function testGetBasePathStream($glob, $basePath) { @@ -790,10 +790,15 @@ public function provideBasePaths() array('/foo/baz\\*/bar', '/foo/baz*'), array('/foo/baz\\\\*/bar', '/foo'), array('/foo/baz\\\\\\*/bar', '/foo/baz\\*'), - array('', ''), ); } + public function provideBasePathsStream() + { + yield from $this->provideBasePaths(); + yield ['', '']; + } + public function testGetBasePathFailsIfNotAbsolute() { $this->expectException(\InvalidArgumentException::class);