8000 bug #28840 add missing double-quotes to extra_fields output message (… · symfony/symfony@5145084 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5145084

Browse files
committed
bug #28840 add missing double-quotes to extra_fields output message (danielkay)
This PR was squashed before being merged into the 2.8 branch (closes #28840). Discussion ---------- add missing double-quotes to extra_fields output message | Q | A | ------------- | --- | Branch? | 2.8 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | N/A | License | MIT | Doc PR | N/A When using the extra_fields_message option on FormTypes to include the extra_fields items in the message, the output included some superfluous (or, perhaps, missing?) quotes. This resulted in some strange output: `This form should not contain extra fields: notes1\", \"notes2\", \"notes3`. This PR removes the quotes and instead implodes the extra_fields array using merely ', ' as the glue, resulting in the output: `This form should not contain extra fields: notes1, notes2, notes3`. Commits ------- 9e74141 add missing double-quotes to extra_fields output message
2 parents c6b288e + 9e74141 commit 5145084

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,13 @@ public function validate($form, Constraint $constraint)
162162
if ($this->context instanceof ExecutionContextInterface) {
163163
$this->context->setConstraint($constraint);
164164
$this->context->buildViolation($config->getOption('extra_fields_message'))
165-
->setParameter('{{ extra_fields }}', implode('", "', array_keys($form->getExtraData())))
165+
->setParameter('{{ extra_fields }}', '"'.implode('", "', array_keys($form->getExtraData())).'"')
166166
->setInvalidValue($form->getExtraData())
167167
->setCode(Form::NO_SUCH_FIELD_ERROR)
168168
->addViolation();
169169
} else {
170170
$this->buildViolation($config->getOption('extra_fields_message'))
171-
->setParameter('{{ extra_fields }}', implode('", "', array_keys($form->getExtraData())))
171+
->setParameter('{{ extra_fields }}', '"'.implode('", "', array_keys($form->getExtraData())).'"')
172172
->setInvalidValue($form->getExtraData())
173173
->setCode(Form::NO_SUCH_FIELD_ERROR)
174174
->addViolation();

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,12 +620,33 @@ public function testViolationIfExtraData()
620620
$this->validator->validate($form, new Form());
621621

622622
$this->buildViolation('Extra!')
623-
->setParameter('{{ extra_fields }}', 'foo')
623+
->setParameter('{{ extra_fields }}', '"foo"')
624624
->setInvalidValue(array('foo' => 'bar'))
625625
->setCode(Form::NO_SUCH_FIELD_ERROR)
626626
->assertRaised();
627627
}
628628

629+
public function testViolationFormatIfMultipleExtraFields()
630+
{
631+
$form = $this->getBuilder('parent', null, array('extra_fields_message' => 'Extra!'))
632+
->setCompound(true)
633+
->setDataMapper($this->getDataMapper())
634+
->add($this->getBuilder('child'))
635+
->getForm();
636+
637+
$form->submit(array('foo' => 'bar', 'baz' => 'qux', 'quux' => 'quuz'));
638+
639+
$this->expectNoValidate();
640+
641+
$this->validator->validate($form, new Form());
642+
643+
$this->buildViolation('Extra!')
644+
->setParameter('{{ extra_fields }}', '"foo", "baz", "quux"')
645+
->setInvalidValue(array('foo' => 'bar', 'baz' => 'qux', 'quux' => 'quuz'))
646+
->setCode(Form::NO_SUCH_FIELD_ERROR)
647+
->assertRaised();
648+
}
649+
629650
public function testNoViolationIfAllowExtraData()
630651
{
631652
$context = $this->getMockExecutionContext();

0 commit comments

Comments
 (0)
0