Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 45769db

Browse filesBrowse files
committed
[Constrainst] Expression language allow null
1 parent 4bdc0f4 commit 45769db
Copy full SHA for 45769db

File tree

Expand file treeCollapse file tree

2 files changed

+18
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+18
-0
lines changed

‎src/Symfony/Component/Validator/Constraints/ExpressionLanguageSyntaxValidator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/ExpressionLanguageSyntaxValidator.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ public function validate($expression, Constraint $constraint): void
3939
throw new UnexpectedTypeException($constraint, ExpressionLanguageSyntax::class);
4040
}
4141

42+
if (null === $expression || '' === $expression) {
43+
return;
44+
}
45+
4246
if (!\is_string($expression)) {
4347
throw new UnexpectedValueException($expression, 'string');
4448
}

‎src/Symfony/Component/Validator/Tests/Constraints/ExpressionLanguageSyntaxValidatorTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Tests/Constraints/ExpressionLanguageSyntaxValidatorTest.php
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,18 @@ public function testExpressionIsNotValid()
6565
->setCode(ExpressionLanguageSyntax::EXPRESSION_LANGUAGE_SYNTAX_ERROR)
6666
->assertRaised();
6767
}
68+
69+
public function testNullIsValid()
70+
{
71+
$this->validator->validate(null, new ExpressionLanguageSyntax());
72+
73+
$this->assertNoViolation();
74+
}
75+
76+
public function testEmptyIsValid()
77+
{
78+
$this->validator->validate('', new ExpressionLanguageSyntax());
79+
80+
$this->assertNoViolation();
81+
}
6882
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.