Skip to content

Commit

Permalink
bug #28840 add missing double-quotes to extra_fields output message (…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
fabpot committed Oct 17, 2018
2 parents c6b288e + 9e74141 commit 5145084
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,13 @@ public function validate($form, Constraint $constraint)
if ($this->context instanceof ExecutionContextInterface) {
$this->context->setConstraint($constraint);
$this->context->buildViolation($config->getOption('extra_fields_message'))
->setParameter('{{ extra_fields }}', implode('", "', array_keys($form->getExtraData())))
->setParameter('{{ extra_fields }}', '"'.implode('", "', array_keys($form->getExtraData())).'"')
->setInvalidValue($form->getExtraData())
->setCode(Form::NO_SUCH_FIELD_ERROR)
->addViolation();
} else {
$this->buildViolation($config->getOption('extra_fields_message'))
->setParameter('{{ extra_fields }}', implode('", "', array_keys($form->getExtraData())))
->setParameter('{{ extra_fields }}', '"'.implode('", "', array_keys($form->getExtraData())).'"')
->setInvalidValue($form->getExtraData())
->setCode(Form::NO_SUCH_FIELD_ERROR)
->addViolation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -620,12 +620,33 @@ public function testViolationIfExtraData()
$this->validator->validate($form, new Form());

$this->buildViolation('Extra!')
->setParameter('{{ extra_fields }}', 'foo')
->setParameter('{{ extra_fields }}', '"foo"')
->setInvalidValue(array('foo' => 'bar'))
->setCode(Form::NO_SUCH_FIELD_ERROR)
->assertRaised();
}

public function testViolationFormatIfMultipleExtraFields()
{
$form = $this->getBuilder('parent', null, array('extra_fields_message' => 'Extra!'))
->setCompound(true)
->setDataMapper($this->getDataMapper())
->add($this->getBuilder('child'))
->getForm();

$form->submit(array('foo' => 'bar', 'baz' => 'qux', 'quux' => 'quuz'));

$this->expectNoValidate();

$this->validator->validate($form, new Form());

$this->buildViolation('Extra!')
->setParameter('{{ extra_fields }}', '"foo", "baz", "quux"')
->setInvalidValue(array('foo' => 'bar', 'baz' => 'qux', 'quux' => 'quuz'))
->setCode(Form::NO_SUCH_FIELD_ERROR)
->assertRaised();
}

public function testNoViolationIfAllowExtraData()
{
$context = $this->getMockExecutionContext();
Expand Down

0 comments on commit 5145084

Please sign in to comment.