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 committed 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
['[email protected]'],
['[email protected]'],
['[email protected]'],
['[email protected]'],
['user+mailbox/[email protected]'],
Expand Down Expand Up @@ -149,4 +150,4 @@ public function getRecords(string $host, int $type): DNSRecords
$validation->isValid('[email protected]', new EmailLexer());
$this->assertEquals($expectedError, $validation->getError());
}
}
}

0 comments on commit 3a85486

Please sign in to comment.