diff --git a/src/Hostname.php b/src/Hostname.php index 6eaa7ab48..9a1e167ad 100644 --- a/src/Hostname.php +++ b/src/Hostname.php @@ -1977,6 +1977,14 @@ public function isValid($value) return true; } + // Handle Regex compilation failure that may happen on .biz domain with has @ character, eg: tapi4457@hsoqvf.biz + // Technically, hostname with '@' character is invalid, so mark as invalid immediately + // @see https://github.com/laminas/laminas-validator/issues/8 + if (strpos($value, '@') !== false) { + $this->error(self::INVALID_HOSTNAME); + return false; + } + // Local hostnames are allowed to be partial (ending '.') if ($this->getAllow() & self::ALLOW_LOCAL) { if (substr($value, -1) === '.') { diff --git a/test/HostnameTest.php b/test/HostnameTest.php index 99921f024..324913e75 100644 --- a/test/HostnameTest.php +++ b/test/HostnameTest.php @@ -721,6 +721,12 @@ public function testValidBizHostname() $this->assertTrue($validator->isValid('google.biz')); } + public function testInValidHostnameWithAt() + { + $validator = new Hostname(); + $this->assertFalse($validator->isValid('tapi4457@hsoqvf.biz')); + } + public function testHostnameWithEmptyDomainPart() { $validator = new Hostname();