From 4e652c91aec5dc1b93960c9fa018fb5ae5e5ff31 Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Sat, 13 Feb 2021 15:59:19 -0500 Subject: [PATCH] Account for localhost/testing sites in domain checks --- app/Support/Utils.php | 4 ++++ tests/UtilsTest.php | 1 + 2 files changed, 5 insertions(+) diff --git a/app/Support/Utils.php b/app/Support/Utils.php index d5924e80..393091d4 100644 --- a/app/Support/Utils.php +++ b/app/Support/Utils.php @@ -123,6 +123,10 @@ class Utils return $val; } + if ($result->hostname === 'localhost') { + return 'localhost'; + } + // Couldn't validate a domain, see if this is an IP address? if (filter_var($url, FILTER_VALIDATE_IP)) { return $url; diff --git a/tests/UtilsTest.php b/tests/UtilsTest.php index 1f4ce27f..11ec1714 100644 --- a/tests/UtilsTest.php +++ b/tests/UtilsTest.php @@ -100,5 +100,6 @@ class UtilsTest extends TestCase $this->assertEquals('phpvms.co.uk', Utils::getRootDomain('http://phpvms.co.uk')); $this->assertEquals('phpvms.co.uk', Utils::getRootDomain('http://www.phpvms.co.uk')); $this->assertEquals('127.0.0.1', Utils::getRootDomain('http://127.0.0.1')); + $this->assertEquals('localhost', Utils::getRootDomain('http://localhost')); } }