mirror of
https://github.com/egulias/EmailValidator.git
synced 2026-08-30 03:59:20 +00:00
Merge pull request #33 from egulias/32_strict_and_dns_bug
#32 - Fixed usage of DNS check and strict parameter
This commit is contained in:
@@ -84,7 +84,7 @@ class EmailValidator
|
||||
return false;
|
||||
}
|
||||
|
||||
$dns = true;
|
||||
$dns = false;
|
||||
if ($checkDNS) {
|
||||
$dns = $this->checkDNS();
|
||||
}
|
||||
@@ -95,7 +95,12 @@ class EmailValidator
|
||||
return false;
|
||||
}
|
||||
|
||||
return ($strict) ? (!$this->hasWarnings() && $dns) : true;
|
||||
return ($strict) ? $this->checkStrict($dns) : true;
|
||||
}
|
||||
|
||||
private function checkStrict($dns)
|
||||
{
|
||||
return !($this->hasWarnings() && !$dns);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -144,16 +149,9 @@ class EmailValidator
|
||||
|
||||
protected function checkDNS()
|
||||
{
|
||||
$checked = false;
|
||||
if (!function_exists('dns_get_record') && (
|
||||
in_array(self::DNSWARN_NO_RECORD, $this->warnings) &&
|
||||
in_array(self::DNSWARN_NO_MX_RECORD, $this->warnings)
|
||||
)) {
|
||||
return $checked;
|
||||
}
|
||||
$checked = true;
|
||||
|
||||
$result = checkdnsrr(trim($this->parser->getParsedDomainPart()), 'MX');
|
||||
$checked = true;
|
||||
|
||||
if (!$result) {
|
||||
$this->warnings[] = self::DNSWARN_NO_RECORD;
|
||||
|
||||
@@ -303,4 +303,14 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public function testInvalidEmailsWithDNSAndStrict()
|
||||
{
|
||||
$this->assertFalse($this->validator->isValid('test@test', true, true));
|
||||
}
|
||||
|
||||
public function testInvalidEmailsWithStrict()
|
||||
{
|
||||
$this->assertFalse($this->validator->isValid('"test"@test', false, true));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user