Browse Source

Fix #17573: `EmailValidator` with `checkDNS=true` throws `ErrorException` on bad domains on Alpine

tags/2.0.29
Evgeny 5 years ago committed by Alexander Makarov
parent
commit
f8611d170d
  1. 2
      framework/CHANGELOG.md
  2. 26
      framework/validators/EmailValidator.php

2
framework/CHANGELOG.md

@ -4,7 +4,7 @@ Yii Framework 2 Change Log
2.0.29 under development
------------------------
- no changes in this release.
- Bug #17573: `EmailValidator` with `checkDNS=true` throws `ErrorException` on bad domains on Alpine (batyrmastyr)
2.0.28 October 08, 2019

26
framework/validators/EmailValidator.php

@ -8,6 +8,7 @@
namespace yii\validators;
use Yii;
use yii\base\ErrorException;
use yii\base\InvalidConfigException;
use yii\helpers\Json;
use yii\web\JsExpression;
@ -111,21 +112,24 @@ class EmailValidator extends Validator
*/
protected function isDNSValid($domain)
{
if (checkdnsrr($domain . '.', 'MX')) {
$mxRecords = dns_get_record($domain . '.', DNS_MX);
if ($mxRecords !== false && count($mxRecords) > 0) {
return true;
}
return $this->hasDNSRecord($domain, true) || $this->hasDNSRecord($domain, false);
}
private function hasDNSRecord($domain, $isMX)
{
$normalizedDomain = $domain . '.';
if (!checkdnsrr($normalizedDomain, ($isMX ? 'MX' : 'A'))) {
return false;
}
if (checkdnsrr($domain . '.', 'A')) {
$aRecords = dns_get_record($domain . '.', DNS_A);
if ($aRecords !== false && count($aRecords) > 0) {
return true;
}
try {
// dns_get_record can return false and emit Warning that may or may not be converted to ErrorException
$records = dns_get_record($normalizedDomain, ($isMX ? DNS_MX : DNS_A));
} catch (ErrorException $exception) {
return false;
}
return false;
return !empty($records);
}
private function idnToAscii($idn)

Loading…
Cancel
Save