Skip to content

Commit 570c154

Browse files
Fix S3 adapter to use correct path separator and update related tests (#57497)
* Fix S3 adapter to use correct path separator and update related tests * Fix S3 adapter to use correct path separator and update related tests (and undid pint-formatting of test names) * Fix S3 adapter to use normal Slash-separator for path prefixing * Refactor S3 Adapter prefixer initialization --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
1 parent a471bfe commit 570c154

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/Illuminate/Filesystem/AwsS3V3Adapter.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Illuminate\Support\Traits\Conditionable;
77
use League\Flysystem\FilesystemAdapter as FlysystemAdapter;
88
use League\Flysystem\FilesystemOperator;
9+
use League\Flysystem\PathPrefixer;
910

1011
class AwsS3V3Adapter extends FilesystemAdapter
1112
{
@@ -31,6 +32,10 @@ public function __construct(FilesystemOperator $driver, FlysystemAdapter $adapte
3132
parent::__construct($driver, $adapter, $config);
3233

3334
$this->client = $client;
35+
36+
$this->prefixer = isset($config['prefix'])
37+
? new PathPrefixer($this->prefixer->prefixPath($config['prefix']), '/')
38+
: new PathPrefixer($config['root'] ?? '', '/');
3439
}
3540

3641
/**

tests/Filesystem/FilesystemAdapterTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,21 @@ public function testProvidesTemporaryUrlsForS3Adapter()
715715
$this->assertTrue($filesystemAdapter->providesTemporaryUrls());
716716
}
717717

718+
public function testUsesRightSeperatorForS3Adapter()
719+
{
720+
$filesystem = new FilesystemManager(new Application);
721+
$filesystemAdapter = $filesystem->createS3Driver([
722+
'region' => 'us-west-1',
723+
'bucket' => 'laravel',
724+
'root' => 'something',
725+
'directory_separator' => '\\',
726+
]);
727+
728+
$path = $filesystemAdapter->path('different');
729+
$this->assertStringContainsString('/', $path);
730+
$this->assertStringNotContainsString('\\', $path);
731+
}
732+
718733
public function testProvidesTemporaryUrlsForAdapterWithoutTemporaryUrlSupport()
719734
{
720735
$filesystemAdapter = new FilesystemAdapter($this->filesystem, $this->adapter);

0 commit comments

Comments
 (0)