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 56f24d0

Browse filesBrowse files
committed
Fixed the null value exception case.
1 parent c927c48 commit 56f24d0
Copy full SHA for 56f24d0

File tree

2 files changed

+16
-0
lines changed
Filter options

2 files changed

+16
-0
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/ValidValidator.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ public function validate($value, Constraint $constraint)
2626
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Valid');
2727
}
2828

29+
if (null === $value) {
30+
return;
31+
}
32+
2933
$this->context
3034
->getValidator()
3135
->inContext($this->context)

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Tests/Constraints/ValidValidatorTest.php
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ public function testPropertyPathsArePassedToNestedContexts()
2020
$this->assertSame('fooBar.fooBarBaz.foo', $violations->get(0)->getPropertyPath());
2121
}
2222

23+
public function testNullValues()
24+
{
25+
$validatorBuilder = new ValidatorBuilder();
26+
$validator = $validatorBuilder->enableAnnotationMapping()->getValidator();
27+
28+
$foo = new Foo();
29+
$foo->fooBar = null;
30+
$violations = $validator->validate($foo, null, array('nested'));
31+
32+
$this->assertCount(0, $violations);
33+
}
34+
2335
protected function createValidator()
2436
{
2537
return new ValidValidator();

0 commit comments

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