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 ad95227

Browse filesBrowse files
committed
bug #21208 [Validator] Add object handling of invalid constraints in Composite (SenseException)
This PR was submitted for the master branch but it was merged into the 2.7 branch instead (closes #21208). Discussion ---------- [Validator] Add object handling of invalid constraints in Composite | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #21206 | License | MIT | Doc PR | n/a This PR fixes a minor bug described in #21206. The constraint `Symfony\Component\Validator\Constraints\Composite` doesn't check in it's exception handling if the wrongly created instance of a nested constraint is an object, which is the expected type for a constraint. Commits ------- 4bd2c22 [Validator] Add object handling of invalid constraints in Composite
2 parents f9b64a2 + 4bd2c22 commit ad95227
Copy full SHA for ad95227

File tree

2 files changed

+15
-0
lines changed
Filter options

2 files changed

+15
-0
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/Composite.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ public function __construct($options = null)
6767

6868
foreach ($nestedConstraints as $constraint) {
6969
if (!$constraint instanceof Constraint) {
70+
if (is_object($constraint)) {
71+
$constraint = get_class($constraint);
72+
}
73+
7074
throw new ConstraintDefinitionException(sprintf('The value %s is not an instance of Constraint in constraint %s', $constraint, get_class($this)));
7175
}
7276

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Tests/Constraints/CompositeTest.php
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,17 @@ public function testFailIfNoConstraint()
125125
));
126126
}
127127

128+
/**
129+
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
130+
*/
131+
public function testFailIfNoConstraintObject()
132+
{
133+
new ConcreteComposite(array(
134+
new NotNull(array('groups' => 'Default')),
135+
new \ArrayObject(),
136+
));
137+
}
138+
128139
/**
129140
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
130141
*/

0 commit comments

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