Skip to content

Commit aeef894

Browse files
committed
Greedy matching caused boundary string to contain quotation mark, making it invalid for determining part boundaries
1 parent 248202e commit aeef894

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
@@ -93,7 +93,7 @@ public function __construct($uploadMaxFilesize = null, $maxFileUploads = null)
9393
public function parse(ServerRequestInterface $request)
9494
{
9595
$contentType = $request->getHeaderLine('content-type');
96-
if(!\preg_match('/boundary="?(.*)"?$/', $contentType, $matches)) {
96+
if(!\preg_match('/boundary="?(.*?)"?$/', $contentType, $matches)) {
9797
return $request;
9898
}
9999

tests/Io/MultipartParserTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,39 @@ public function testPostKey()
6666
);
6767
}
6868

69+
public function testPostWithQuotationMarkEncapsulatedBoundary()
70+
{
71+
$boundary = "---------------------------5844729766471062541057622570";
72+
73+
$data = "--$boundary\r\n";
74+
$data .= "Content-Disposition: form-data; name=\"users[one]\"\r\n";
75+
$data .= "\r\n";
76+
$data .= "single\r\n";
77+
$data .= "--$boundary\r\n";
78+
$data .= "Content-Disposition: form-data; name=\"users[two]\"\r\n";
79+
$data .= "\r\n";
80+
$data .= "second\r\n";
81+
$data .= "--$boundary--\r\n";
82+
83+
$request = new ServerRequest('POST', 'http://example.com/', array(
84+
'Content-Type' => 'multipart/form-data; boundary="' . $boundary . '"',
85+
), $data, 1.1);
86+
87+
$parser = new MultipartParser();
88+
$parsedRequest = $parser->parse($request);
89+
90+
$this->assertEmpty($parsedRequest->getUploadedFiles());
91+
$this->assertSame(
92+
array(
93+
'users' => array(
94+
'one' => 'single',
95+
'two' => 'second',
96+
),
97+
),
98+
$parsedRequest->getParsedBody()
99+
);
100+
}
101+
69102
public function testPostStringOverwritesMap()
70103
{
71104
$boundary = "---------------------------5844729766471062541057622570";

0 commit comments

Comments
 (0)