Skip to content

Commit b7c1c23

Browse files
Merge branch '6.4' into 7.0
* 6.4: (33 commits) [Console][FrameworkBundle][HttpKernel][WebProfilerBundle] Enable profiling commands [AssetMapper] Disable profiler when the "dev server" respond Adds translations for Portuguese (pt) [AssetMapper] Link needs as="style" Allow Symfony 7.0 on Phrase translation provider [Mime] Throw InvalidArgumentException on invalid form field type inside array [Mailer][Bridges] Allow Symfony 7 [Tests] Use `JsonMockResponse` where applicable [FrameworkBundle][HttpKernel] Introduce `$buildDir` argument to `WarmableInterface::warmup` to warm read-only artefacts in `build_dir` [ErrorHandler] Fix expected missing return types [Form] Fix merging params & files when "multiple" is enabled [HttpFoundation] Do not swallow trailing `=` in cookie value Fix markdown in README files Handle Sendinblue error responses without a message key Handle Brevo error responses without a message key [Scheduler] Add failureEvent [Notifier][Bridges] Allow Symfony 7 [Mailer][Brevo][Sendinblue] Fix typo [Serializer] Fix collecting only first missing constructor argument [ErrorHandler] Fix file link format call in trace view ...
2 parents a5096b7 + ca4f58b commit b7c1c23

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

Part/Multipart/FormDataPart.php

+5-6
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,8 @@ public function __construct(array $fields = [])
3232
{
3333
parent::__construct();
3434

35-
foreach ($fields as $name => $value) {
36-
if (!\is_string($value) && !\is_array($value) && !$value instanceof TextPart) {
37-
throw new InvalidArgumentException(sprintf('The value of the form field "%s" can only be a string, an array, or an instance of TextPart ("%s" given).', $name, get_debug_type($value)));
38-
}
35+
$this->fields = $fields;
3936

40-
$this->fields[$name] = $value;
41-
}
4237
// HTTP does not support \r\n in header values
4338
$this->getHeaders()->setMaxLineLength(\PHP_INT_MAX);
4439
}
@@ -75,6 +70,10 @@ private function prepareFields(array $fields): array
7570
return;
7671
}
7772

73+
if (!\is_string($item) && !$item instanceof TextPart) {
74+
throw new InvalidArgumentException(sprintf('The value of the form field "%s" can only be a string, an array, or an instance of TextPart, "%s" given.', $fieldName, get_debug_type($item)));
75+
}
76+
7877
$values[] = $this->preparePart($fieldName, $item);
7978
};
8079

Tests/Part/Multipart/FormDataPartTest.php

+16
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,22 @@ public function testExceptionOnFormFieldsWithIntegerKeysAndMultipleValues()
199199
$f->getParts();
200200
}
201201

202+
public function testExceptionOnFormFieldsWithDisallowedTypesInsideArray()
203+
{
204+
$f = new FormDataPart([
205+
'foo' => [
206+
'bar' => 'baz',
207+
'qux' => [
208+
'quux' => 1,
209+
],
210+
],
211+
]);
212+
213+
$this->expectException(InvalidArgumentException::class);
214+
$this->expectExceptionMessage('The value of the form field "foo[qux][quux]" can only be a string, an array, or an instance of TextPart, "int" given.');
215+
$f->getParts();
216+
}
217+
202218
public function testToString()
203219
{
204220
$p = DataPart::fromPath($file = __DIR__.'/../../Fixtures/mimetypes/test.gif');

0 commit comments

Comments
 (0)