From 0fadf67c5d87bd047f91de6c7e0abe26a3a8c2e6 Mon Sep 17 00:00:00 2001 From: Ahmed Ammar Date: Mon, 1 Apr 2024 01:40:26 +0200 Subject: [PATCH] Ignore invalid paths --- cli/Valet/Server.php | 4 ++++ tests/ServerTest.php | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/cli/Valet/Server.php b/cli/Valet/Server.php index 0436f5c6..ccf05c82 100644 --- a/cli/Valet/Server.php +++ b/cli/Valet/Server.php @@ -160,6 +160,10 @@ public function sitePath(string $siteName): ?string $domain = static::domainFromSiteName($siteName); foreach ($this->config['paths'] as $path) { + if (! is_dir($path)) { + continue; + } + $handle = opendir($path); if ($handle === false) { diff --git a/tests/ServerTest.php b/tests/ServerTest.php index 55243a92..b9691343 100644 --- a/tests/ServerTest.php +++ b/tests/ServerTest.php @@ -90,6 +90,13 @@ public function test_it_returns_null_default_site_path_if_not_set() $this->assertNull($server->defaultSitePath()); } + public function test_it_ignores_invalid_paths() + { + $server = new Server(['paths' => ['fake' => __DIR__.'/invalid_path']]); + + $this->assertNull($server->sitePath('tighten')); + } + public function test_it_tests_whether_host_is_ip_address() { $this->assertTrue(Server::hostIsIpAddress('192.168.1.1'));