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 07d99c2

Browse filesBrowse files
committed
bug #16897 [Form] Fix constraints could be null if not set (DZunke)
This PR was squashed before being merged into the 2.3 branch (closes #16897). Discussion ---------- [Form] Fix constraints could be null if not set | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - If the form options has no key for constraints the default should be an empty array to be ignored by the loop in the FormValidator. The default without this fix is ```null``` and foreach will throw an error. The "Bug" also still exists in master-Branch. Commits ------- f80e0eb [Form] Fix constraints could be null if not set
2 parents 414365d + f80e0eb commit 07d99c2
Copy full SHA for 07d99c2

File tree

2 files changed

+12
-1
lines changed
Filter options

2 files changed

+12
-1
lines changed

‎src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function validate($form, Constraint $constraint)
4545

4646
// Validate the data against the constraints defined
4747
// in the form
48-
$constraints = $config->getOption('constraints');
48+
$constraints = $config->getOption('constraints', array());
4949
foreach ($constraints as $constraint) {
5050
foreach ($groups as $group) {
5151
if (in_array($group, $constraint->groups)) {

‎src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,17 @@ public function testDontValidateIfParentWithoutCascadeValidation()
123123
$this->assertNoViolation();
124124
}
125125

126+
public function testNotExistingConstraintIndex()
127+
{
128+
$object = new \stdClass();
129+
$form = new FormBuilder('name', '\stdClass', $this->dispatcher, $this->factory);
130+
$form = $form->setData($object)->getForm();
131+
132+
$this->validator->validate($form, new Form());
133+
134+
$this->assertNoViolation();
135+
}
136+
126137
public function testValidateConstraintsEvenIfNoCascadeValidation()
127138
{
128139
$object = $this->getMock('\stdClass');

0 commit comments

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