Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x] Asset Container returns relative url for same site #11372

Open
wants to merge 6 commits into
base: 5.x
Choose a base branch
from
Open
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: 3 additions & 1 deletion src/Assets/AssetContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use Statamic\Facades\Stache;
use Statamic\Facades\URL;
use Statamic\Support\Arr;
use Statamic\Support\Str;
use Statamic\Support\Traits\FluentlyGetsAndSets;

class AssetContainer implements Arrayable, ArrayAccess, AssetContainerContract, Augmentable
Expand Down Expand Up @@ -138,7 +139,8 @@ public function url()
return null;
}

$url = rtrim($this->disk()->url('/'), '/');
$url = Str::removeRight($this->disk()->url('/'), '/');
$url = Str::removeLeft($url, config('app.url'));
edalzell marked this conversation as resolved.
Show resolved Hide resolved

marcorieser marked this conversation as resolved.
Show resolved Hide resolved
return ($url === '') ? '/' : $url;
}
Expand Down
15 changes: 15 additions & 0 deletions tests/Assets/AssetContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,21 @@ public function it_gets_the_url_from_the_disk_config_when_its_relative()
$this->assertEquals('http://localhost/container', $container->absoluteUrl());
}

#[Test]
public function it_gets_the_url_from_the_disk_config_when_its_app_url()
{
config(['filesystems.disks.test' => [
'driver' => 'local',
'root' => __DIR__.'/__fixtures__/container',
'url' => 'http://localhost/container',
]]);

$container = (new AssetContainer)->disk('test');

$this->assertEquals('/container', $container->url());
$this->assertEquals('http://localhost/container', $container->absoluteUrl());
}

#[Test]
public function its_private_if_the_disk_has_no_url()
{
Expand Down
Loading