diff --git a/src/Symfony/Component/Form/Tests/AbstractRequestHandlerTestCase.php b/src/Symfony/Component/Form/Tests/AbstractRequestHandlerTestCase.php index c61447a1ddc68..a68c8f8a0511f 100644 --- a/src/Symfony/Component/Form/Tests/AbstractRequestHandlerTestCase.php +++ b/src/Symfony/Component/Form/Tests/AbstractRequestHandlerTestCase.php @@ -14,6 +14,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\Form\Extension\Core\DataMapper\DataMapper; +use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Form; use Symfony\Component\Form\FormBuilder; use Symfony\Component\Form\FormError; @@ -236,6 +237,24 @@ public function testMergeParamsAndFiles($method) $this->assertSame($file, $form->get('field2')->getData()); } + public function testIntegerChildren() + { + $form = $this->createForm('root', 'POST', true); + $form->add('0', TextType::class); + $form->add('1', TextType::class); + + $this->setRequestData('POST', [ + 'root' => [ + '1' => 'bar', + ], + ]); + + $this->requestHandler->handleRequest($form, $this->request); + + $this->assertNull($form->get('0')->getData()); + $this->assertSame('bar', $form->get('1')->getData()); + } + /** * @dataProvider methodExceptGetProvider */ diff --git a/src/Symfony/Component/Form/Util/FormUtil.php b/src/Symfony/Component/Form/Util/FormUtil.php index 6c7873de70cb6..56b99ec119f0e 100644 --- a/src/Symfony/Component/Form/Util/FormUtil.php +++ b/src/Symfony/Component/Form/Util/FormUtil.php @@ -50,20 +50,21 @@ public static function isEmpty($data) */ public static function mergeParamsAndFiles(array $params, array $files): array { - $result = []; + if (array_is_list($files)) { + foreach ($files as $value) { + $params[] = $value; + } + + return $params; + } foreach ($params as $key => $value) { if (\is_array($value) && \is_array($files[$key] ?? null)) { - $value = self::mergeParamsAndFiles($value, $files[$key]); + $params[$key] = self::mergeParamsAndFiles($value, $files[$key]); unset($files[$key]); } - if (\is_int($key)) { - $result[] = $value; - } else { - $result[$key] = $value; - } } - return array_merge($result, $files); + return array_replace($params, $files); } }