Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/Symfony/Component/Mime/Part/Multipart/FormDataPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,17 @@ public function getParts(): array
private function prepareFields(array $fields): array
{
$values = [];
array_walk_recursive($fields, function ($item, $key) use (&$values) {
if (!\is_array($item)) {
$values[] = $this->preparePart($key, $item);
$prepare = function ($item, $key, $root = null) use (&$values, &$prepare) {
if (\is_array($item)) {
array_walk($item, $prepare, $root ?: $key);

return;
}
});

$values[] = $this->preparePart($root ?: $key, $item);
};

array_walk($fields, $prepare);

return $values;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,45 @@

class FormDataPartTest extends TestCase
{
public function testConstructorWithMultidimensionalParams()
{
$r = new \ReflectionProperty(TextPart::class, 'encoding');
$r->setAccessible(true);

$b = new TextPart('content');
$c = DataPart::fromPath($file = __DIR__.'/../../Fixtures/mimetypes/test.gif');
$f = new FormDataPart([
'foo' => [
$content =
'very very long content that will not be cut even if the length i way more than 76 characters, ok?',
$content,
],
'bar' => [
clone $b,
clone $b,
],
'baz' => [
clone $c,
clone $c,
],
]);

$t = new TextPart($content, 'utf-8', 'plain', '8bit');
$t->setDisposition('form-data');
$t->setName('foo');
$t->getHeaders()->setMaxLineLength(PHP_INT_MAX);
$b->setDisposition('form-data');
$b->setName('bar');
$b->getHeaders()->setMaxLineLength(PHP_INT_MAX);
$r->setValue($b, '8bit');
$c->setDisposition('form-data');
$c->setName('baz');
$c->getHeaders()->setMaxLineLength(PHP_INT_MAX);
$r->setValue($c, '8bit');

$this->assertEquals([$t, $t, $b, $b, $c, $c], $f->getParts());
}

public function testConstructor()
{
$r = new \ReflectionProperty(TextPart::class, 'encoding');
Expand Down