Skip to content

Commit f07a923

Browse files
committed
Regex would only work for header parameters that are encapsulate between quotation marks, causing form field names without not to be matched.
1 parent aeef894 commit f07a923

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

src/Io/MultipartParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ private function parseHeaders($header)
278278
private function getParameterFromHeader(array $header, $parameter)
279279
{
280280
foreach ($header as $part) {
281-
if (\preg_match('/' . $parameter . '="?(.*)"$/', $part, $matches)) {
281+
if (\preg_match('/' . $parameter . '="?(.*?)"?$/', $part, $matches)) {
282282
return $matches[1];
283283
}
284284
}

tests/Io/MultipartParserTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,39 @@ public function testPostWithQuotationMarkEncapsulatedBoundary()
9999
);
100100
}
101101

102+
public function testPostFormDataNamesWithoutQuotationMark()
103+
{
104+
$boundary = "---------------------------5844729766471062541057622570";
105+
106+
$data = "--$boundary\r\n";
107+
$data .= "Content-Disposition: form-data; name=users[one]\r\n";
108+
$data .= "\r\n";
109+
$data .= "single\r\n";
110+
$data .= "--$boundary\r\n";
111+
$data .= "Content-Disposition: form-data; name=users[two]\r\n";
112+
$data .= "\r\n";
113+
$data .= "second\r\n";
114+
$data .= "--$boundary--\r\n";
115+
116+
$request = new ServerRequest('POST', 'http://example.com/', array(
117+
'Content-Type' => 'multipart/form-data; boundary="' . $boundary . '"',
118+
), $data, 1.1);
119+
120+
$parser = new MultipartParser();
121+
$parsedRequest = $parser->parse($request);
122+
123+
$this->assertEmpty($parsedRequest->getUploadedFiles());
124+
$this->assertSame(
125+
array(
126+
'users' => array(
127+
'one' => 'single',
128+
'two' => 'second',
129+
),
130+
),
131+
$parsedRequest->getParsedBody()
132+
);
133+
}
134+
102135
public function testPostStringOverwritesMap()
103136
{
104137
$boundary = "---------------------------5844729766471062541057622570";

0 commit comments

Comments
 (0)