Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Validator] add domain test for windows check dns #27559

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add test valid domain
  • Loading branch information
oliviervangest committed Jun 12, 2018
commit e4e75aa919f4a81ab9ca3d62c0bc9dddec54f987
21 changes: 15 additions & 6 deletions src/Symfony/Component/Validator/Constraints/EmailValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/
class EmailValidator extends ConstraintValidator
{
const DOMAIN_PATTERN = '/^[a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9]\.[a-zA-Z]{2,}$/';
private $isStrict;

/**
Expand Down Expand Up @@ -95,10 +96,6 @@ public function validate($value, Constraint $constraint)

$host = (string) substr($value, strrpos($value, '@') + 1);

if ('.' !== substr($host, -1)) {
$host .= '.';
}

// Check for host DNS resource records
if ($constraint->checkMX) {
if (!$this->checkMX($host)) {
Expand Down Expand Up @@ -133,6 +130,18 @@ public function validate($value, Constraint $constraint)
}
}

/**
* Check if host domain is valid
*
* @param string $host Host
*
* @return bool
*/
private function checkHostDomain($host)
{
return preg_match(static::DOMAIN_PATTERN, $host);
}

/**
* Check DNS Records for MX type.
*
Expand All @@ -142,7 +151,7 @@ public function validate($value, Constraint $constraint)
*/
private function checkMX($host)
{
return '' !== $host && checkdnsrr($host, 'MX');
return $this->checkHostDomain($host) && checkdnsrr($host, 'MX');
}

/**
Expand All @@ -154,6 +163,6 @@ private function checkMX($host)
*/
private function checkHost($host)
{
return '' !== $host && ($this->checkMX($host) || (checkdnsrr($host, 'A') || checkdnsrr($host, 'AAAA')));
return $this->checkHostDomain($host) && ($this->checkMX($host) || (checkdnsrr($host, 'A') || checkdnsrr($host, 'AAAA')));
}
}
1 change: 1 addition & 0 deletions src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public function getInvalidEmails()
array('example'),
array('example@'),
array('example@localhost'),
array('example@gmailcom'),
array('[email protected] bar'),
);
}
Expand Down