diff --git a/src/Symfony/Component/Validator/Constraints/Email.php b/src/Symfony/Component/Validator/Constraints/Email.php index 912878de763c..e9e0e06d3b8b 100644 --- a/src/Symfony/Component/Validator/Constraints/Email.php +++ b/src/Symfony/Component/Validator/Constraints/Email.php @@ -62,6 +62,10 @@ public function __construct( throw new InvalidArgumentException('The "mode" parameter value is not valid.'); } + if (null !== $mode && !\in_array($mode, self::$validationModes, true)) { + throw new InvalidArgumentException('The "mode" parameter value is not valid.'); + } + parent::__construct($options, $groups, $payload); $this->message = $message ?? $this->message; diff --git a/src/Symfony/Component/Validator/Tests/Constraints/EmailTest.php b/src/Symfony/Component/Validator/Tests/Constraints/EmailTest.php index bf719b6f848f..3451fdfb208e 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/EmailTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/EmailTest.php @@ -33,6 +33,13 @@ public function testUnknownModesTriggerException() new Email(['mode' => 'Unknown Mode']); } + public function testUnknownModeArgumentsTriggerException() + { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('The "mode" parameter value is not valid.'); + new Email(null, null, 'Unknown Mode'); + } + public function testNormalizerCanBeSet() { $email = new Email(['normalizer' => 'trim']);