Skip to content

Commit 3a85486

Browse files
authored
DNS record check now passes if email address has no top-level domain (#355)
1 parent db4c314 commit 3a85486

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/Validation/DNSCheckValidation.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,20 @@ protected function checkDns($host)
123123
{
124124
$variant = INTL_IDNA_VARIANT_UTS46;
125125

126-
$host = rtrim(idn_to_ascii($host, IDNA_DEFAULT, $variant), '.') . '.';
126+
$host = rtrim(idn_to_ascii($host, IDNA_DEFAULT, $variant), '.');
127127

128-
return $this->validateDnsRecords($host);
128+
$hostParts = explode('.', $host);
129+
$host = array_pop($hostParts);
130+
131+
while (count($hostParts) > 0) {
132+
$host = array_pop($hostParts) . '.' . $host;
133+
134+
if ($this->validateDnsRecords($host)) {
135+
return true;
136+
}
137+
}
138+
139+
return false;
129140
}
130141

131142

tests/EmailValidator/Validation/DNSCheckValidationTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public function validEmailsProvider()
2121
return [
2222
// dot-atom
2323
['Abc@ietf.org'],
24+
['Abc@fake.ietf.org'],
2425
['ABC@ietf.org'],
2526
['Abc.123@ietf.org'],
2627
['user+mailbox/department=shipping@ietf.org'],
@@ -149,4 +150,4 @@ public function getRecords(string $host, int $type): DNSRecords
149150
$validation->isValid('example@invalid.example.com', new EmailLexer());
150151
$this->assertEquals($expectedError, $validation->getError());
151152
}
152-
}
153+
}

0 commit comments

Comments
 (0)