Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 08f5d7c

Browse filesBrowse files
l-naumannnicolas-grekas
authored andcommitted
[Mime] Throw InvalidArgumentException on invalid form field type inside array
1 parent abe5555 commit 08f5d7c
Copy full SHA for 08f5d7c

File tree

Expand file treeCollapse file tree

2 files changed

+21
-6
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+21
-6
lines changed

‎src/Symfony/Component/Mime/Part/Multipart/FormDataPart.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mime/Part/Multipart/FormDataPart.php
+5-6Lines changed: 5 additions & 6 deletions
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

‎src/Symfony/Component/Mime/Tests/Part/Multipart/FormDataPartTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mime/Tests/Part/Multipart/FormDataPartTest.php
+16Lines changed: 16 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.