Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit afab3ee

Browse files
committed
bug #11676 [Form] Fixed #11675 ValueToDuplicatesTransformer accept "0" value (Nek-)
This PR was submitted for the master branch but it was merged into the 2.3 branch instead (closes #11676). Discussion ---------- [Form] Fixed #11675 ValueToDuplicatesTransformer accept "0" value | Q | A | ------------- | --- | Bug fix? | [yes] | New feature? | [no] | BC breaks? | [no] | Deprecations? | [no] | Tests pass? | [yes] | Fixed tickets | #11675 | License | MIT Commits ------- 31d48ab Fixed #11675 ValueToDuplicatesTransformer accept "0" value
2 parents 3d59e34 + 31d48ab commit afab3ee

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/Symfony/Component/Form/Extension/Core/DataTransformer/ValueToDuplicatesTransformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function reverseTransform($array)
6464
$emptyKeys = array();
6565

6666
foreach ($this->keys as $key) {
67-
if (!empty($array[$key])) {
67+
if (isset($array[$key]) && '' !== $array[$key] && false !== $array[$key] && array() !== $array[$key]) {
6868
if ($array[$key] !== $result) {
6969
throw new TransformationFailedException(
7070
'All values in the array should be the same'

src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/ValueToDuplicatesTransformerTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,29 @@ public function testReverseTransformCompletelyNull()
8282
$this->assertNull($this->transformer->reverseTransform($input));
8383
}
8484

85+
public function testReverseTransformEmptyArray()
86+
{
87+
$input = array(
88+
'a' => array(),
89+
'b' => array(),
90+
'c' => array(),
91+
);
92+
93+
$this->assertNull($this->transformer->reverseTransform($input));
94+
}
95+
96+
97+
public function testReverseTransformZeroString()
98+
{
99+
$input = array(
100+
'a' => '0',
101+
'b' => '0',
102+
'c' => '0'
103+
);
104+
105+
$this->assertSame('0', $this->transformer->reverseTransform($input));
106+
}
107+
85108
/**
86109
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
87110
*/

0 commit comments

Comments
 (0)