From 3a85486b709bc384dae8eb78fb2eec649bdb64ff Mon Sep 17 00:00:00 2001 From: KergeKacsa Date: Sat, 14 Jan 2023 15:17:03 +0100 Subject: [PATCH] DNS record check now passes if email address has no top-level domain (#355) --- src/Validation/DNSCheckValidation.php | 15 +++++++++++++-- .../Validation/DNSCheckValidationTest.php | 3 ++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Validation/DNSCheckValidation.php b/src/Validation/DNSCheckValidation.php index d9ffaad..214d4f4 100644 --- a/src/Validation/DNSCheckValidation.php +++ b/src/Validation/DNSCheckValidation.php @@ -123,9 +123,20 @@ protected function checkDns($host) { $variant = INTL_IDNA_VARIANT_UTS46; - $host = rtrim(idn_to_ascii($host, IDNA_DEFAULT, $variant), '.') . '.'; + $host = rtrim(idn_to_ascii($host, IDNA_DEFAULT, $variant), '.'); - return $this->validateDnsRecords($host); + $hostParts = explode('.', $host); + $host = array_pop($hostParts); + + while (count($hostParts) > 0) { + $host = array_pop($hostParts) . '.' . $host; + + if ($this->validateDnsRecords($host)) { + return true; + } + } + + return false; } diff --git a/tests/EmailValidator/Validation/DNSCheckValidationTest.php b/tests/EmailValidator/Validation/DNSCheckValidationTest.php index ed9dd84..610a295 100644 --- a/tests/EmailValidator/Validation/DNSCheckValidationTest.php +++ b/tests/EmailValidator/Validation/DNSCheckValidationTest.php @@ -21,6 +21,7 @@ public function validEmailsProvider() return [ // dot-atom ['Abc@ietf.org'], + ['Abc@fake.ietf.org'], ['ABC@ietf.org'], ['Abc.123@ietf.org'], ['user+mailbox/department=shipping@ietf.org'], @@ -149,4 +150,4 @@ public function getRecords(string $host, int $type): DNSRecords $validation->isValid('example@invalid.example.com', new EmailLexer()); $this->assertEquals($expectedError, $validation->getError()); } -} \ No newline at end of file +}