diff --git a/src/Symfony/Component/Validator/Constraints/ExpressionLanguageSyntaxValidator.php b/src/Symfony/Component/Validator/Constraints/ExpressionLanguageSyntaxValidator.php index 4b67da2c2be9c..7a3530239c611 100644 --- a/src/Symfony/Component/Validator/Constraints/ExpressionLanguageSyntaxValidator.php +++ b/src/Symfony/Component/Validator/Constraints/ExpressionLanguageSyntaxValidator.php @@ -39,6 +39,10 @@ public function validate($expression, Constraint $constraint): void throw new UnexpectedTypeException($constraint, ExpressionLanguageSyntax::class); } + if (null === $expression || '' === $expression) { + return; + } + if (!\is_string($expression)) { throw new UnexpectedValueException($expression, 'string'); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/ExpressionLanguageSyntaxValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/ExpressionLanguageSyntaxValidatorTest.php index 8cca54ed8a730..e87853129ffe8 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/ExpressionLanguageSyntaxValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/ExpressionLanguageSyntaxValidatorTest.php @@ -42,6 +42,21 @@ public function testExpressionWithoutNames() $this->assertNoViolation(); } + public function testExpressionEmpty() + { + $this->validator->validate(null, new ExpressionLanguageSyntax([ + 'message' => 'myMessage', + ])); + + $this->assertNoViolation(); + + $this->validator->validate('', new ExpressionLanguageSyntax([ + 'message' => 'myMessage', + ])); + + $this->assertNoViolation(); + } + public function testExpressionWithAllowedVariableName() { $this->validator->validate('a + 1', new ExpressionLanguageSyntax([
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: