From be725711852ef4bb0458a32b300dfac124ef257d Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Sat, 15 Aug 2020 13:50:58 -0400 Subject: [PATCH] Check if the root domain is an IP address --- app/Support/Utils.php | 10 +++++++++- tests/UtilsTest.php | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/Support/Utils.php b/app/Support/Utils.php index 98455e24..d5924e80 100644 --- a/app/Support/Utils.php +++ b/app/Support/Utils.php @@ -118,6 +118,14 @@ class Utils $extract = new Extract(); $result = $extract->parse($url); - return $result->getRegistrableDomain(); + $val = $result->getRegistrableDomain(); + if (!empty($val)) { + return $val; + } + + // 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 2ac01c3f..f4d04866 100644 --- a/tests/UtilsTest.php +++ b/tests/UtilsTest.php @@ -86,6 +86,7 @@ class UtilsTest extends TestCase $tests = [ 'http://phpvms.net', 'https://phpvms.net', + 'https://phpvms.net/', 'phpvms.net', 'https://phpvms.net/index.php', 'https://demo.phpvms.net', @@ -98,5 +99,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('52.249.193.184', Utils::getRootDomain('http://52.249.193.184')); } }