diff --git a/CHANGELOG.md b/CHANGELOG.md index dcd011148..083bf8dd5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ All notable changes to this project will be documented in this file, in reverse chronological order by release. -## 2.10.3 - TBD +## 2.10.3 - 2018-12-13 ### Added @@ -22,6 +22,9 @@ All notable changes to this project will be documented in this file, in reverse ### Fixed +- [#241](https://github.com/zendframework/zend-validator/pull/241) has the `Hostname` validator return an invalid result early when an empty + domain segment is detected. + - [#232](https://github.com/zendframework/zend-validator/pull/232) updates the `Hostname` validator to allow underscores in subdomains. - [#218](https://github.com/zendframework/zend-validator/pull/218) fixes a precision issue with the `Step` validator. diff --git a/src/Hostname.php b/src/Hostname.php index 4c5fe4a81..a97d787d1 100644 --- a/src/Hostname.php +++ b/src/Hostname.php @@ -2092,6 +2092,13 @@ public function isValid($value) } } + // 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; + break 2; + } + // Check dash (-) does not start, end or appear in 3rd and 4th positions if ($utf8StrWrapper->strpos($domainPart, '-') === 0 || ($utf8StrWrapper->strlen($domainPart) > 2 diff --git a/test/HostnameTest.php b/test/HostnameTest.php index a6f4be76b..562a3a5c2 100644 --- a/test/HostnameTest.php +++ b/test/HostnameTest.php @@ -701,4 +701,10 @@ public function testValidBizHostname() $validator = new Hostname(); $this->assertTrue($validator->isValid('google.biz')); } + + public function testHostnameWithEmptyDomainPart() + { + $validator = new Hostname(); + $this->assertFalse($validator->isValid('.com')); + } }