Compare commits

...

2 Commits

Author SHA1 Message Date
Eduardo Gulias Davis 5c3a79217c Merge pull request #33 from egulias/32_strict_and_dns_bug
#32 - Fixed usage of DNS check and strict parameter
2014-11-03 00:13:57 +01:00
Eduardo Gulias Davis 749b423775 #32 - Fixed usage of DNS check and strict parameter 2014-11-03 00:05:58 +01:00
2 changed files with 18 additions and 10 deletions
+8 -10
View File
@@ -84,7 +84,7 @@ class EmailValidator
return false; return false;
} }
$dns = true; $dns = false;
if ($checkDNS) { if ($checkDNS) {
$dns = $this->checkDNS(); $dns = $this->checkDNS();
} }
@@ -95,7 +95,12 @@ class EmailValidator
return false; 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() protected function checkDNS()
{ {
$checked = false; $checked = true;
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;
}
$result = checkdnsrr(trim($this->parser->getParsedDomainPart()), 'MX'); $result = checkdnsrr(trim($this->parser->getParsedDomainPart()), 'MX');
$checked = true;
if (!$result) { if (!$result) {
$this->warnings[] = self::DNSWARN_NO_RECORD; $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));
}
} }