Skip to content
Merged
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: 2 additions & 2 deletions src/Facades/Endpoint/URL.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,11 +438,11 @@ private function ensureSiteCaches(): void
$sites = Site::all();

self::$hasRelativeSiteCache = $sites->contains(
fn ($site) => Str::startsWith((string) ($site->rawConfig()['url'] ?? ''), '/')
fn ($site) => Str::startsWith((string) $site->url(), '/')
);

self::$absoluteSiteUrlsCache = $sites
->map(fn ($site) => $site->rawConfig()['url'] ?? null)
->map(fn ($site) => $site->url())
->filter(fn ($siteUrl) => self::isAbsolute($siteUrl))
->map(fn ($siteUrl) => self::getDomainFromAbsolute($siteUrl));

Expand Down
35 changes: 35 additions & 0 deletions tests/Facades/UrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,41 @@ public function it_does_not_trust_current_request_domain_when_no_sites_are_relat
$this->assertFalse(URL::isExternalToApplication('http://this-site.com/'));
}

#[Test]
public function it_determines_external_url_to_application_when_site_urls_are_configured_with_antlers()
{
config(['app.frontend_url' => 'http://frontend-site.com']);

$this->setSites([
'en' => ['name' => 'English', 'locale' => 'en_US', 'url' => '{{ config:app:frontend_url }}'],
'fr' => ['name' => 'French', 'locale' => 'fr_FR', 'url' => '{{ config:app:frontend_url }}/fr'],
]);

$this->assertFalse(URL::isExternalToApplication('http://frontend-site.com/'));
$this->assertFalse(URL::isExternalToApplication('http://frontend-site.com/fr/'));
$this->assertTrue(URL::isExternalToApplication('http://external-site.com/'));
}

#[Test]
public function it_tidies_urls_on_site_hosts_configured_with_antlers()
{
config(['app.frontend_url' => 'http://frontend-site.com']);

$this->setSites([
'en' => ['name' => 'English', 'locale' => 'en_US', 'url' => '{{ config:app:frontend_url }}'],
'fr' => ['name' => 'French', 'locale' => 'fr_FR', 'url' => '{{ config:app:frontend_url }}/fr'],
]);

$this->assertSame('http://frontend-site.com', URL::tidy('http://frontend-site.com/'));
$this->assertSame('http://frontend-site.com/fr', URL::tidy('http://frontend-site.com/fr/'));
$this->assertSame('http://external-site.com/page/', URL::tidy('http://external-site.com/page/'));

URL::enforceTrailingSlashes();

$this->assertSame('http://frontend-site.com/fr/', URL::tidy('http://frontend-site.com/fr'));
$this->assertSame('http://external-site.com/page', URL::tidy('http://external-site.com/page'));
}

#[Test]
#[DataProvider('assembleProvider')]
public function it_can_assemble_urls($segments, $assembled)
Expand Down
Loading