Skip to content
Closed
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
4 changes: 2 additions & 2 deletions src/Storage/Device/S3.php
Original file line number Diff line number Diff line change
Expand Up @@ -636,8 +636,8 @@ public function exists(string $path): bool
$prefix = $root.'/'.ltrim($path, '/');
}

if (! empty($path) && ! str_ends_with($prefix, '/')) {
$prefix .= '/';
if (! empty($path) && str_ends_with($path, '/')) {
$prefix = rtrim($prefix, '/').'/';
}

$objects = $this->listObjects($prefix, 1);
Expand Down
19 changes: 19 additions & 0 deletions tests/Storage/S3Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,25 @@ public function testDirectoryExists()
$this->assertEquals(false, $this->object->exists($this->object->getPath('nested/deep/structure')));
}

/**
* Test that file paths without trailing slash don't incorrectly match directories
* Verifies fix: exists('file.html') should not return true when directory 'file.html/' exists
*/
public function testFileExistsDoesNotMatchDirectoryPrefix()
{
$this->object->write($this->object->getPath('builds/index.html'), 'content', 'text/html');
$this->object->write($this->object->getPath('builds/other.css'), 'body {}', 'text/css');

$this->assertEquals(true, $this->object->exists($this->object->getPath('builds/index.html')));

$this->object->delete($this->object->getPath('builds/index.html'));

// File should not exist even though directory 'builds/' still contains other.css
$this->assertEquals(false, $this->object->exists($this->object->getPath('builds/index.html')));

$this->object->delete($this->object->getPath('builds/other.css'));
}

public function testMove()
{
$this->assertEquals(true, $this->object->write($this->object->getPath('text-for-move.txt'), 'Hello World', 'text/plain'));
Expand Down