Skip to content

Commit

Permalink
FIX Ensure public url slashes are forward slashes
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed May 15, 2024
1 parent 82e5f58 commit 7266f83
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Flysystem/PublicAssetAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
28 changes: 28 additions & 0 deletions tests/php/PublicAssetAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 7266f83

Please sign in to comment.