From 7266f8337a3cb3a3ce9842b1a7fcf93623e71262 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Wed, 15 May 2024 12:41:24 +1200 Subject: [PATCH] FIX Ensure public url slashes are forward slashes --- src/Flysystem/PublicAssetAdapter.php | 1 + tests/php/PublicAssetAdapterTest.php | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/Flysystem/PublicAssetAdapter.php b/src/Flysystem/PublicAssetAdapter.php index eef2129b..21448570 100644 --- a/src/Flysystem/PublicAssetAdapter.php +++ b/src/Flysystem/PublicAssetAdapter.php @@ -53,6 +53,7 @@ protected function findRoot($root) */ public function getPublicUrl($path) { + $path = Convert::slashes($path, '/'); return Controller::join_links(Director::baseURL(), $this->parentUrlPrefix, $path); } diff --git a/tests/php/PublicAssetAdapterTest.php b/tests/php/PublicAssetAdapterTest.php index dacfa3c7..d39cd24b 100644 --- a/tests/php/PublicAssetAdapterTest.php +++ b/tests/php/PublicAssetAdapterTest.php @@ -28,4 +28,32 @@ public function testInitBaseURL() $adapter->getPublicUrl('dir/file.jpg') ); } + + public function provideGetPublicUrl(): array + { + return [ + 'filename' => [ + 'path' => 'lorem.jpg', + 'expected' => '/baseurl/assets/lorem.jpg', + ], + 'unixPath' => [ + 'path' => 'path/to/lorem.jpg', + 'expected' => '/baseurl/assets/path/to/lorem.jpg', + ], + 'windowsPath' => [ + 'path' => 'path\\to\\lorem.jpg', + 'expected' => '/baseurl/assets/path/to/lorem.jpg', + ], + ]; + } + + /** + * @dataProvider provideGetPublicUrl + */ + public function testGetPublicUrl(string $path, string $expected) + { + $adapter = new PublicAssetAdapter('assets'); + $actual = $adapter->getPublicUrl($path); + $this->assertSame($expected, $actual); + } }