File tree Expand file tree Collapse file tree 2 files changed +28
-8
lines changed
Expand file tree Collapse file tree 2 files changed +28
-8
lines changed Original file line number Diff line number Diff line change 1414use PHPUnit \Framework \TestCase ;
1515use Symfony \Component \EventDispatcher \EventDispatcher ;
1616use Symfony \Component \Form \Extension \Core \DataMapper \DataMapper ;
17+ use Symfony \Component \Form \Extension \Core \Type \TextType ;
1718use Symfony \Component \Form \Form ;
1819use Symfony \Component \Form \FormBuilder ;
1920use Symfony \Component \Form \FormError ;
@@ -236,6 +237,24 @@ public function testMergeParamsAndFiles($method)
236237 $ this ->assertSame ($ file , $ form ->get ('field2 ' )->getData ());
237238 }
238239
240+ public function testIntegerChildren ()
241+ {
242+ $ form = $ this ->createForm ('root ' , 'POST ' , true );
243+ $ form ->add ('0 ' , TextType::class);
244+ $ form ->add ('1 ' , TextType::class);
245+
246+ $ this ->setRequestData ('POST ' , [
247+ 'root ' => [
248+ '1 ' => 'bar ' ,
249+ ],
250+ ]);
251+
252+ $ this ->requestHandler ->handleRequest ($ form , $ this ->request );
253+
254+ $ this ->assertNull ($ form ->get ('0 ' )->getData ());
255+ $ this ->assertSame ('bar ' , $ form ->get ('1 ' )->getData ());
256+ }
257+
239258 /**
240259 * @dataProvider methodExceptGetProvider
241260 */
Original file line number Diff line number Diff line change @@ -50,20 +50,21 @@ public static function isEmpty($data)
5050 */
5151 public static function mergeParamsAndFiles (array $ params , array $ files ): array
5252 {
53- $ result = [];
53+ if (array_is_list ($ files )) {
54+ foreach ($ files as $ value ) {
55+ $ params [] = $ value ;
56+ }
57+
58+ return $ params ;
59+ }
5460
5561 foreach ($ params as $ key => $ value ) {
5662 if (\is_array ($ value ) && \is_array ($ files [$ key ] ?? null )) {
57- $ value = self ::mergeParamsAndFiles ($ value , $ files [$ key ]);
63+ $ params [ $ key ] = self ::mergeParamsAndFiles ($ value , $ files [$ key ]);
5864 unset($ files [$ key ]);
5965 }
60- if (\is_int ($ key )) {
61- $ result [] = $ value ;
62- } else {
63- $ result [$ key ] = $ value ;
64- }
6566 }
6667
67- return array_merge ( $ result , $ files );
68+ return array_replace ( $ params , $ files );
6869 }
6970}
You can’t perform that action at this time.
0 commit comments