From 4feeb4bb0c8dd97d948bfcecf3b2f5386149b03b Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 14 Aug 2020 21:38:50 +0700 Subject: [PATCH 1/3] Possible fixes #8 Signed-off-by: Abdul Malik Ikhsan --- src/Hostname.php | 5 +++++ test/HostnameTest.php | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/src/Hostname.php b/src/Hostname.php index 6eaa7ab48..887976561 100644 --- a/src/Hostname.php +++ b/src/Hostname.php @@ -1977,6 +1977,11 @@ public function isValid($value) return true; } + if (mb_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(); From 0a6abbb428dad0565ba12a28250a3065e486bdd8 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sun, 16 Aug 2020 07:18:36 +0700 Subject: [PATCH 2/3] using strpos instead Signed-off-by: Abdul Malik Ikhsan --- src/Hostname.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Hostname.php b/src/Hostname.php index 887976561..e14ff05d9 100644 --- a/src/Hostname.php +++ b/src/Hostname.php @@ -1977,7 +1977,7 @@ public function isValid($value) return true; } - if (mb_strpos($value, '@') !== false) { + if (strpos($value, '@') !== false) { $this->error(self::INVALID_HOSTNAME); return false; } From 4a808c8fbcf5a14672c3de1bbcf957a0b3624ca5 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 17 Sep 2020 02:32:59 +0700 Subject: [PATCH 3/3] add comment indicating issue that resolved with at check @ addition Signed-off-by: Abdul Malik Ikhsan --- src/Hostname.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Hostname.php b/src/Hostname.php index e14ff05d9..9a1e167ad 100644 --- a/src/Hostname.php +++ b/src/Hostname.php @@ -1977,6 +1977,9 @@ 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;