Skip to content

Commit

Permalink
[5.x] Asset Container returns relative url for same site (#11372)
Browse files Browse the repository at this point in the history
Co-authored-by: Jason Varga <[email protected]>
  • Loading branch information
marcorieser and jasonvarga authored Feb 25, 2025
1 parent 6af62e5 commit b35e734
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 4 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,9 @@ public function url()
return null;
}

$url = rtrim($this->disk()->url('/'), '/');
$url = (string) Str::of($this->disk()->url('/'))
->rtrim('/')
->after(config('app.url'));

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

0 comments on commit b35e734

Please sign in to comment.