Skip to content

[Validator][Email] - Strict validation and soft dependency #9140

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 16 commits into from
Closed
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
#1581 - Recover MX and Host validation
  • Loading branch information
egulias committed Jan 12, 2014
commit 1052f3b67c48eb4864c4e4d0d681e69194616828
21 changes: 19 additions & 2 deletions src/Symfony/Component/Validator/Constraints/EmailValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,34 @@ public function validate($value, Constraint $constraint)
$valid = preg_match('/.+\@.+\..+/', $value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is filter_var() replaced by preg_match()? Doesn't it change the existing behaviour?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it does, that's why I was saying this is still a BC break. But I did it this way because of the conversation on #1581 where, if I didn't got it wrong, filter_var()was to be replaced by the strict validator and the non-strict validation will be done by a simple regex (see #1581 (comment))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean BC break. BC means the opposite

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes BC break, sorry.
El 04/01/2014 19:59, "Tobias Schultze" notifications@github.com escribió:

In src/Symfony/Component/Validator/Constraints/EmailValidator.php:

@@ -36,12 +50,23 @@ public function validate($value, Constraint $constraint)
}

     $value = (string) $value;
  •    $valid = filter_var($value, FILTER_VALIDATE_EMAIL);
    
  •    if ($constraint->strict === null) {
    
  •        $constraint->strict = $this->isStrict;
    
  •    }
    
  •    if ($constraint->strict === true && class_exists('\Egulias\EmailValidator\EmailValidator')) {
    
  •        $strictValidator = new StrictEmailValidator();
    
  •        $valid = $strictValidator->isValid($value, $constraint->checkMX);
    
  •    } elseif ($constraint->strict === true) {
    
  •        throw new \RuntimeException('Strict email validation requires egulias/email-validator');
    
  •    } else {
    
  •        $valid = preg_match('/.+\@.+..+/', $value);
    

you mean BC break. BC means the opposite


Reply to this email directly or view it on GitHubhttps://github.com//pull/9140/files#r8652639
.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jakzal it's ok? Before I fix the other changes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine with me if it was agreed before :)

}

if ($valid && $constraint->checkHost) {
if ($valid) {
$host = substr($value, strpos($value, '@') + 1);
// Check for host DNS resource records
$valid = $this->checkHost($host);

if ($valid && $constraint->checkMX) {
$valid = $this->checkMX($host);
} elseif ($valid && $constraint->checkHost) {
$valid = $this->checkHost($host);
}
}

if (!$valid) {
$this->context->addViolation($constraint->message, array('{{ value }}' => $value));
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You must also remove this blank line to avoid having 2 blank lines in a row.

/**
* Check DNS Records for MX type.
*
* @param string $host Host
*
* @return Boolean
*/
private function checkMX($host)
{
return checkdnsrr($host, 'MX');
}

/**
* Check if one of MX, A or AAAA DNS RR exists.
*
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy