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

Skip to content

[Form] Fix merging form data and files (ter) #52347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 28, 2023

Conversation

nicolas-grekas
Copy link
Member

Q A
Branch? 5.4
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #52318
License MIT

Adapted from a patch provided by @jan-pintr

The original was like below but this one looks more appropriate to me.

--- a/src/Symfony/Component/Form/Util/FormUtil.php
+++ b/src/Symfony/Component/Form/Util/FormUtil.php
@@ -47,8 +47,12 @@ public static function isEmpty(mixed $data): bool
     public static function mergeParamsAndFiles(array $params, array $files): array
     {
         if (array_is_list($files)) {
-            foreach ($files as $value) {
-                $params[] = $value;
+            foreach ($files as $key => $value) {
+                if (is_array($params[$key])) {
+                    $params[$key] = array_merge($params[$key], $value);
+                } else {
+                    $params[] = $value;
+                }
             }
 
             return $params;
@@ -61,6 +65,6 @@ public static function mergeParamsAndFiles(array $params, array $files): array
             }
         }
 
-        return array_replace($params, $files);
+        return array_merge($params, $files);
     }```

</details>

@nicolas-grekas nicolas-grekas force-pushed the form-zero-indexed-col-reproducer branch from eedb07a to 9facb2f Compare October 28, 2023 16:24
@fabpot
Copy link
Member

fabpot commented Oct 28, 2023

Thank you @nicolas-grekas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants