Skip to content

[Validator] Deprecated email validation mode loose #43505

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 34 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
5929f1c
Deprecating "loose" mode
ThomasLandauer Oct 14, 2021
74f7563
Update EmailValidator.php
ThomasLandauer Oct 14, 2021
0c73136
Update UPGRADE-6.0.md
ThomasLandauer Oct 14, 2021
aed6e3f
Update UPGRADE-6.0.md
ThomasLandauer Oct 27, 2021
0f17b9d
Update UPGRADE-5.4.md
ThomasLandauer Oct 27, 2021
8a76eae
Update CHANGELOG.md
ThomasLandauer Oct 27, 2021
cfa86c7
Update Email.php
ThomasLandauer Oct 27, 2021
67a2150
Update EmailValidator.php
ThomasLandauer Oct 27, 2021
77b3e84
Update CHANGELOG.md
ThomasLandauer Oct 27, 2021
45357c4
Update EmailValidator.php
ThomasLandauer Oct 27, 2021
717b3cf
Update EmailValidator.php
ThomasLandauer Oct 27, 2021
8662b25
Update EmailValidator.php
ThomasLandauer Oct 27, 2021
fd6741c
Moving "loose" check above "null" check
ThomasLandauer Oct 27, 2021
3a9b461
Update EmailValidator.php
ThomasLandauer Oct 27, 2021
cd42408
Update EmailValidatorTest.php
ThomasLandauer Oct 27, 2021
ff9bd5e
Update EmailValidatorTest.php
ThomasLandauer Oct 27, 2021
b6395a7
Update EmailValidatorTest.php
ThomasLandauer Oct 27, 2021
5454b7e
Adding `$this->expectDeprecation();`
ThomasLandauer Oct 27, 2021
23cf718
Update EmailValidatorTest.php
ThomasLandauer Oct 28, 2021
08a59ba
Update EmailValidatorTest.php
ThomasLandauer Oct 28, 2021
356236f
Update ValidationTest.php
ThomasLandauer Oct 28, 2021
71427ac
Update ValidationTest.php
ThomasLandauer Oct 28, 2021
ca4345a
Update EmailValidatorTest.php
ThomasLandauer Oct 28, 2021
e159032
Update EmailValidatorTest.php
ThomasLandauer Oct 28, 2021
ceb9b3d
Update ValidationTest.php
ThomasLandauer Oct 28, 2021
b265fbd
Update EmailValidatorTest.php
ThomasLandauer Oct 28, 2021
a44a14c
Update EmailValidatorTest.php
ThomasLandauer Oct 28, 2021
7a279e9
Update ValidationTest.php
ThomasLandauer Oct 28, 2021
dc52691
Update ValidationTest.php
ThomasLandauer Oct 28, 2021
7b5fca1
Update ValidationTest.php
ThomasLandauer Oct 28, 2021
8dd3937
Update EmailValidatorTest.php
ThomasLandauer Oct 28, 2021
2a90782
Update ValidationTest.php
ThomasLandauer Oct 28, 2021
fd7522e
Renaming `testValidEmails` => `testValidEmailsLoose`
ThomasLandauer Oct 28, 2021
973e624
Update EmailValidatorTest.php
ThomasLandauer Oct 28, 2021
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
5 changes: 5 additions & 0 deletions UPGRADE-5.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,8 @@ Security
}
}
```

Validator
---------

* Deprecated email validation mode `loose`; will be removed in Symfony 6 in favor of `html5` (= new default)
2 changes: 2 additions & 0 deletions UPGRADE-6.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,8 @@ Validator
$builder->enableAnnotationMapping(true)
->addDefaultDoctrineAnnotationReader();
```

* Removed email validation mode `loose`; default is now `html5`

Workflow
--------
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/Validator/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CHANGELOG
* Add a `CssColor` constraint to validate CSS colors
* Add support for `ConstraintViolationList::createFromMessage()`
* Add error's uid to `Count` and `Length` constraints with "exactly" option enabled
* Deprecate email validation mode `loose`, use `html5` instead

5.3
---
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/Validator/Constraints/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Email extends Constraint
{
public const VALIDATION_MODE_HTML5 = 'html5';
public const VALIDATION_MODE_STRICT = 'strict';
/** @deprecated since Symfony 5.4; will be removed in Symfony 6.0; use email validation mode "html5" instead */
public const VALIDATION_MODE_LOOSE = 'loose';

public const INVALID_FORMAT_ERROR = 'bd79c0ab-ddba-46cc-a703-a7a4b08de310';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public function __construct(string $defaultMode = Email::VALIDATION_MODE_LOOSE)
throw new \InvalidArgumentException('The "defaultMode" parameter value is not valid.');
}

if (Email::VALIDATION_MODE_LOOSE === $defaultMode) {
trigger_deprecation('symfony/validator', '5.4', 'The "loose" email validation mode is deprecated, use "html5" instead');
}

$this->defaultMode = $defaultMode;
}

Expand Down Expand Up @@ -69,6 +73,10 @@ public function validate($value, Constraint $constraint)
$value = ($constraint->normalizer)($value);
}

if (Email::VALIDATION_MODE_LOOSE === $constraint->mode) {
trigger_deprecation('symfony/validator', '5.4', 'The "loose" email validation mode is deprecated, use "html5" instead');
}

if (null === $constraint->mode) {
$constraint->mode = $this->defaultMode;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Component\Validator\Tests\Constraints;

use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\EmailValidator;
use Symfony\Component\Validator\Exception\UnexpectedValueException;
Expand All @@ -21,9 +22,11 @@
*/
class EmailValidatorTest extends ConstraintValidatorTestCase
{
use ExpectDeprecationTrait;

protected function createValidator()
{
return new EmailValidator(Email::VALIDATION_MODE_LOOSE);
return new EmailValidator(Email::VALIDATION_MODE_HTML5);
}

public function testUnknownDefaultModeTriggerException()
Expand Down Expand Up @@ -61,16 +64,18 @@ public function testExpectsStringCompatibleType()
}

/**
* @dataProvider getValidEmails
* @group legacy
* @dataProvider getValidEmailsLoose
*/
public function testValidEmails($email)
public function testValidEmailsLoose($email)
{
$this->validator->validate($email, new Email());
$this->validator->validate($email, new Email(['mode' => Email::VALIDATION_MODE_LOOSE]));

$this->expectDeprecation('Since symfony/validator 5.4: The "loose" email validation mode is deprecated, use "html5" instead');
$this->assertNoViolation();
}

public function getValidEmails()
public function getValidEmailsLoose()
{
return [
['fabien@symfony.com'],
Expand Down Expand Up @@ -214,12 +219,16 @@ public function testModeHtml5()
->assertRaised();
}

/**
* @group legacy
*/
public function testModeLoose()
{
$constraint = new Email(['mode' => Email::VALIDATION_MODE_LOOSE]);

$this->validator->validate('example@example..com', $constraint);

$this->expectDeprecation('Since symfony/validator 5.4: The "loose" email validation mode is deprecated, use "html5" instead');
$this->assertNoViolation();
}

Expand Down
8 changes: 4 additions & 4 deletions src/Symfony/Component/Validator/Tests/ValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ class ValidationTest extends TestCase
{
public function testCreateCallableValid()
{
$validator = Validation::createCallable(new Email());
$validator = Validation::createCallable(new Email(['mode' => Email::VALIDATION_MODE_HTML5]));
$this->assertEquals('test@example.com', $validator('test@example.com'));
}

public function testCreateCallableInvalid()
{
$validator = Validation::createCallable(new Email());
$validator = Validation::createCallable(new Email(['mode' => Email::VALIDATION_MODE_HTML5]));
try {
$validator('test');
$this->fail('No ValidationFailedException thrown');
Expand All @@ -44,13 +44,13 @@ public function testCreateCallableInvalid()

public function testCreateIsValidCallableValid()
{
$validator = Validation::createIsValidCallable(new Email());
$validator = Validation::createIsValidCallable(new Email(['mode' => Email::VALIDATION_MODE_HTML5]));
$this->assertTrue($validator('test@example.com'));
}

public function testCreateIsValidCallableInvalid()
{
$validator = Validation::createIsValidCallable(new Email());
$validator = Validation::createIsValidCallable(new Email(['mode' => Email::VALIDATION_MODE_HTML5]));
$this->assertFalse($validator('test', $violations));
$this->assertCount(1, $violations);
$this->assertEquals('This value is not a valid email address.', $violations->get(0)->getMessage());
Expand Down