Skip to content

Commit

Permalink
Merge branch '6.4' into 7.0
Browse files Browse the repository at this point in the history
* 6.4: (31 commits)
  [Messenger] Add call to `gc_collect_cycles()` after each message is handled
  fix tests
  fix tests on AppVeyor
  Hungarian typo fix in validators translation
  [VarDump] Fix order of dumped properties - parent goes first
  DX: drop unused import
  [Validator] updated Latvian translation
  re-introduce conflict rule with WebProfilerBundle < 6.4
  [Validator] Added missing Swedish translations
  [Mailer] [Notifier] #52264 Update Sendinblue / Brevo API host
  [Validator] Added missing Estonian translations #51939
  fix File constraint tests on 32bit PHP
  [Form] Skip merging params & files if there are no files in the first place
  [Translation] Ignore bridges in `.gitattributes` file
  [AssetMapper] Adding import-parsing case where import contains a path
  Add missing Hungarian validator translations
  Added missing Bosnian translations #51929
  add return type hints to EntityFactory
  Update UndefinedCallableHandler with "importmap", "form" and "worflow" filters/functions
  [FrameworkBundle] Fix CommandDataCollector is always registered
  ...
  • Loading branch information
xabbuh committed Oct 25, 2023
2 parents 269f116 + 5a1aa07 commit ebaccca
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
19 changes: 19 additions & 0 deletions Tests/AbstractRequestHandlerTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -227,6 +228,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
*/
Expand Down
17 changes: 9 additions & 8 deletions Util/FormUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,21 @@ public static function isEmpty(mixed $data): bool
*/
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);
}
}

0 comments on commit ebaccca

Please # to comment.