From 81e3e21c401f5d7009cf13cd9cf93af7e95797f4 Mon Sep 17 00:00:00 2001 From: Michael Sanders Date: Thu, 1 Oct 2026 15:05:44 +0200 Subject: [PATCH] Fix broken LAN/IP site extraction (wrong config key) server.php read $valetConfig['tld'] when deciding the site for IP-address (local-network) access, but Valet stores the TLD under the 'domain' key (Configuration seeds 'domain' => 'test' and the rest of the codebase uses it). The missing key yielded null -> coerced to an empty TLD, so Server::valetSiteFromIpAddressUri() matched incorrectly (and emitted a PHP warning/deprecation). Pass $valetConfig['domain'] instead. Add ServerTest coverage for valetSiteFromIpAddressUri (match + no-match). --- server.php | 2 +- tests/Unit/ServerTest.php | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/server.php b/server.php index 84a07f7..6cc6257 100644 --- a/server.php +++ b/server.php @@ -26,7 +26,7 @@ if (Server::hostIsIpAddress($_SERVER['HTTP_HOST'])) { $uriForIpAddressExtraction = ltrim($_SERVER['REQUEST_URI'], '/'); - if ($host = Server::valetSiteFromIpAddressUri($uriForIpAddressExtraction, $valetConfig['tld'])) { + if ($host = Server::valetSiteFromIpAddressUri($uriForIpAddressExtraction, $valetConfig['domain'])) { $_SERVER['HTTP_HOST'] = $host; $_SERVER['REQUEST_URI'] = str_replace($host, '', $uriForIpAddressExtraction); } diff --git a/tests/Unit/ServerTest.php b/tests/Unit/ServerTest.php index 4425260..1e241dc 100644 --- a/tests/Unit/ServerTest.php +++ b/tests/Unit/ServerTest.php @@ -95,4 +95,30 @@ public function it_does_not_treat_a_sibling_prefix_dir_as_inside(): void @rmdir($sibling); } } + + /** + * @test + */ + public function it_extracts_the_valet_site_from_an_ip_address_uri(): void + { + // Mirrors the LAN/IP-access flow: REQUEST_URI is "domain.test/auth/login" + // (leading slash already trimmed) and the TLD comes from config['domain']. + $this->assertSame( + 'my-site.test', + Server::valetSiteFromIpAddressUri('my-site.test/auth/login', 'test') + ); + $this->assertSame( + 'my-site.test', + Server::valetSiteFromIpAddressUri('my-site.test', 'test') + ); + } + + /** + * @test + */ + public function it_returns_null_when_the_ip_address_uri_has_no_matching_tld(): void + { + $this->assertNull(Server::valetSiteFromIpAddressUri('my-site.dev/auth', 'test')); + $this->assertNull(Server::valetSiteFromIpAddressUri('', 'test')); + } }