Skip to content

[Validator] Add common double dot email typo #24429

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 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions UPGRADE-3.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,8 @@ Validator
* Not setting the `strict` option of the `Choice` constraint to `true` is
deprecated and will throw an exception in Symfony 4.0.

* The pattern for used by the `Email` validator will use the html5 email input pattern in Symfony 4.0.

Yaml
----

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
*/
class EmailValidator extends ConstraintValidator
{
const PATTERN_LOOSE = '/^.+\@\S+\.\S+$/';
const PATTERN_HTML5 = '/^[a-zA-Z0-9.!#$%&\'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+$/';

/**
* @var bool
*/
Expand Down Expand Up @@ -78,7 +81,11 @@ public function validate($value, Constraint $constraint)

return;
}
} elseif (!preg_match('/^.+\@\S+\.\S+$/', $value)) {
} elseif (!preg_match(self::PATTERN_LOOSE, $value)) {
if (!preg_match(self::PATTERN_HTML5, $value)) {
@trigger_error('The loose email pattern is deprecated since version 3.4 and will be switched to the html5 email elements pattern in 4.0');
}

$this->context->buildViolation($constraint->message)
->setParameter('{{ value }}', $this->formatValue($value))
->setCode(Email::INVALID_FORMAT_ERROR)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ public function getValidEmails()
);
}

/**
* @group legacy
*/
public function testLegacyPattern()
{
$this->validator->validate('example@example.co..uk', new Email());

$this->assertNoViolation();
}

/**
* @dataProvider getInvalidEmails
*/
Expand Down