Skip to content

Commit

Permalink
Merge pull request #603 from creative-commoners/pulls/2.2/public-url-…
Browse files Browse the repository at this point in the history
…slashes

FIX Ensure public url slashes are forward slashes
  • Loading branch information
GuySartorelli authored May 15, 2024
2 parents 82e5f58 + 7266f83 commit 205c2d5
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 205c2d5

Please sign in to comment.