Account for localhost/testing sites in domain checks

This commit is contained in:
Nabeel Shahzad 2021-02-13 15:59:19 -05:00
parent a6f62045c4
commit 4e652c91ae
2 changed files with 5 additions and 0 deletions

View File

@ -123,6 +123,10 @@ class Utils
return $val; return $val;
} }
if ($result->hostname === 'localhost') {
return 'localhost';
}
// Couldn't validate a domain, see if this is an IP address? // Couldn't validate a domain, see if this is an IP address?
if (filter_var($url, FILTER_VALIDATE_IP)) { if (filter_var($url, FILTER_VALIDATE_IP)) {
return $url; return $url;

View File

@ -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://phpvms.co.uk'));
$this->assertEquals('phpvms.co.uk', Utils::getRootDomain('http://www.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('127.0.0.1', Utils::getRootDomain('http://127.0.0.1'));
$this->assertEquals('localhost', Utils::getRootDomain('http://localhost'));
} }
} }