From 749b423775b592851188764e93b5c27d008aa54c Mon Sep 17 00:00:00 2001 From: Eduardo Gulias Davis Date: Mon, 3 Nov 2014 00:05:58 +0100 Subject: [PATCH] #32 - Fixed usage of DNS check and strict parameter --- src/Egulias/EmailValidator/EmailValidator.php | 18 ++++++++---------- .../EmailValidator/EmailValidatorTest.php | 10 ++++++++++ 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/Egulias/EmailValidator/EmailValidator.php b/src/Egulias/EmailValidator/EmailValidator.php index 80e6227..a3bc1d9 100644 --- a/src/Egulias/EmailValidator/EmailValidator.php +++ b/src/Egulias/EmailValidator/EmailValidator.php @@ -84,7 +84,7 @@ public function isValid($email, $checkDNS = false, $strict = false) return false; } - $dns = true; + $dns = false; if ($checkDNS) { $dns = $this->checkDNS(); } @@ -95,7 +95,12 @@ public function isValid($email, $checkDNS = false, $strict = 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 @@ public function getThreshold() 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; diff --git a/tests/egulias/Tests/EmailValidator/EmailValidatorTest.php b/tests/egulias/Tests/EmailValidator/EmailValidatorTest.php index 0831806..e9e3a6e 100644 --- a/tests/egulias/Tests/EmailValidator/EmailValidatorTest.php +++ b/tests/egulias/Tests/EmailValidator/EmailValidatorTest.php @@ -303,4 +303,14 @@ public function getInvalidEmailsWithWarnings() ), ); } + + public function testInvalidEmailsWithDNSAndStrict() + { + $this->assertFalse($this->validator->isValid('test@test', true, true)); + } + + public function testInvalidEmailsWithStrict() + { + $this->assertFalse($this->validator->isValid('"test"@test', false, true)); + } }