Skip to content

Commit

Permalink
DNS record check now passes if email address has no top-level domain (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
kergekacsa authored Jan 14, 2023
1 parent db4c314 commit 3a85486
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
15 changes: 13 additions & 2 deletions src/Validation/DNSCheckValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand Down
3 changes: 2 additions & 1 deletion tests/EmailValidator/Validation/DNSCheckValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down Expand Up @@ -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());
}
}
}

0 comments on commit 3a85486

Please sign in to comment.