From fd3d55003b2d996533114f28600a66b498be80ce Mon Sep 17 00:00:00 2001 From: andreasschroth Date: Wed, 3 Oct 2018 13:02:48 +0200 Subject: [PATCH 1/4] Skip further checks in case of empty domain part Fixes issue #240 --- src/Hostname.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Hostname.php b/src/Hostname.php index 97d543bc4..59a472d64 100644 --- a/src/Hostname.php +++ b/src/Hostname.php @@ -2098,6 +2098,13 @@ public function isValid($value) return false; } } + + // Stop with following checks if domain part is empty, as it definitely is not a valid hostname then + if ($domainPart === '') { + $this->error(self::INVALID_HOSTNAME); + $status = false; + break 2; + } // Check dash (-) does not start, end or appear in 3rd and 4th positions if ($utf8StrWrapper->strpos($domainPart, '-') === 0 From c8c703d82925477b931959bef4afb5a4e68e6cfa Mon Sep 17 00:00:00 2001 From: andreasschroth Date: Wed, 3 Oct 2018 13:21:08 +0200 Subject: [PATCH 2/4] Add test for hostname with empty domain part --- test/HostnameTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/HostnameTest.php b/test/HostnameTest.php index 64b28f14a..45ae230b3 100644 --- a/test/HostnameTest.php +++ b/test/HostnameTest.php @@ -647,4 +647,11 @@ public function testValidBizHostname() $validator = new Hostname(); $this->assertTrue($validator->isValid('google.biz')); } + + + public function testHostnameWithEmptyDomainPart() + { + $validator = new Hostname(); + $this->assertFalse($validator->isValid('.com')); + } } From c7ccaa20321c37627e6f6b05d6b314158295da5e Mon Sep 17 00:00:00 2001 From: andreasschroth Date: Wed, 3 Oct 2018 13:28:12 +0200 Subject: [PATCH 3/4] Fix codestyle. --- src/Hostname.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Hostname.php b/src/Hostname.php index 59a472d64..bfaa80239 100644 --- a/src/Hostname.php +++ b/src/Hostname.php @@ -2098,8 +2098,8 @@ public function isValid($value) return false; } } - - // Stop with following checks if domain part is empty, as it definitely is not a valid hostname then + + // Skip following checks if domain part is empty, as it definitely is not a valid hostname then if ($domainPart === '') { $this->error(self::INVALID_HOSTNAME); $status = false; From 081fd6b6177c0746dd73b51a178e5adee5c16f66 Mon Sep 17 00:00:00 2001 From: andreasschroth Date: Wed, 3 Oct 2018 13:33:33 +0200 Subject: [PATCH 4/4] Fix codestyle. --- test/HostnameTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/HostnameTest.php b/test/HostnameTest.php index 45ae230b3..9c0960b6a 100644 --- a/test/HostnameTest.php +++ b/test/HostnameTest.php @@ -647,8 +647,7 @@ public function testValidBizHostname() $validator = new Hostname(); $this->assertTrue($validator->isValid('google.biz')); } - - + public function testHostnameWithEmptyDomainPart() { $validator = new Hostname();