Skip to content
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

[Validator]  detect wrong e-mail validation modes #54751

Merged
merged 1 commit into from Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Symfony/Component/Validator/Constraints/Email.php
Expand Up @@ -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;
Expand Down
Expand Up @@ -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']);
Expand Down