Skip to content

Commit a54a4fc

Browse files
committed
Fixed #1882: Prevent listing directory named 0 from returning unfiltered responses.
1 parent ccf2ba2 commit a54a4fc

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

src/AdapterTestUtilities/FilesystemAdapterTestCase.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,21 @@ public function writing_a_file_with_an_empty_stream(): void
225225
});
226226
}
227227

228+
/**
229+
* @test
230+
*/
231+
public function listing_a_directory_named_0(): void
232+
{
233+
$this->givenWeHaveAnExistingFile('0/path.txt');
234+
$this->givenWeHaveAnExistingFile('1/path.txt');
235+
236+
$this->runScenario(function () {
237+
$listing = iterator_to_array($this->adapter()->listContents('0', false));
238+
239+
$this->assertCount(1, $listing);
240+
});
241+
}
242+
228243
/**
229244
* @test
230245
*/

src/AsyncAwsS3/AsyncAwsS3Adapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ public function listContents(string $path, bool $deep): iterable
299299
{
300300
$path = trim($path, '/');
301301
$prefix = trim($this->prefixer->prefixPath($path), '/');
302-
$prefix = empty($prefix) ? '' : $prefix . '/';
302+
$prefix = $prefix === '' ? '' : $prefix . '/';
303303
$options = ['Bucket' => $this->bucket, 'Prefix' => $prefix];
304304

305305
if (false === $deep) {

src/AwsS3V3/AwsS3V3Adapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ public function fileSize(string $path): FileAttributes
375375
public function listContents(string $path, bool $deep): iterable
376376
{
377377
$prefix = trim($this->prefixer->prefixPath($path), '/');
378-
$prefix = empty($prefix) ? '' : $prefix . '/';
378+
$prefix = $prefix === '' ? '' : $prefix . '/';
379379
$options = ['Bucket' => $this->bucket, 'Prefix' => $prefix];
380380

381381
if ($deep === false) {

src/GoogleCloudStorage/GoogleCloudStorageAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ public function listContents(string $path, bool $deep): iterable
310310
$prefixedPath = $this->prefixer->prefixPath($path);
311311
$prefixes = $options = [];
312312

313-
if ( ! empty($prefixedPath)) {
313+
if ($prefixedPath !== '') {
314314
$options = ['prefix' => sprintf('%s/', rtrim($prefixedPath, '/'))];
315315
}
316316

0 commit comments

Comments
 (0)