diff --git a/src/Symfony/Component/Mime/Part/Multipart/FormDataPart.php b/src/Symfony/Component/Mime/Part/Multipart/FormDataPart.php index 75d69a88a08fc..36bab4325a766 100644 --- a/src/Symfony/Component/Mime/Part/Multipart/FormDataPart.php +++ b/src/Symfony/Component/Mime/Part/Multipart/FormDataPart.php @@ -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; } diff --git a/src/Symfony/Component/Mime/Tests/Part/Multipart/FormDataPartTest.php b/src/Symfony/Component/Mime/Tests/Part/Multipart/FormDataPartTest.php index 127fce000a532..bf35814348592 100644 --- a/src/Symfony/Component/Mime/Tests/Part/Multipart/FormDataPartTest.php +++ b/src/Symfony/Component/Mime/Tests/Part/Multipart/FormDataPartTest.php @@ -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');
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: