Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Io/MultipartParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function __construct($uploadMaxFilesize = null, $maxFileUploads = null)
public function parse(ServerRequestInterface $request)
{
$contentType = $request->getHeaderLine('content-type');
if(!\preg_match('/boundary="?(.*)"?$/', $contentType, $matches)) {
if(!\preg_match('/boundary="?(.*?)"?$/', $contentType, $matches)) {
return $request;
}

Expand Down Expand Up @@ -278,7 +278,7 @@ private function parseHeaders($header)
private function getParameterFromHeader(array $header, $parameter)
{
foreach ($header as $part) {
if (\preg_match('/' . $parameter . '="?(.*)"$/', $part, $matches)) {
if (\preg_match('/' . $parameter . '="?(.*?)"?$/', $part, $matches)) {
return $matches[1];
}
}
Expand Down
66 changes: 66 additions & 0 deletions tests/Io/MultipartParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,72 @@ public function testPostKey()
);
}

public function testPostWithQuotationMarkEncapsulatedBoundary()
{
$boundary = "---------------------------5844729766471062541057622570";

$data = "--$boundary\r\n";
$data .= "Content-Disposition: form-data; name=\"users[one]\"\r\n";
$data .= "\r\n";
$data .= "single\r\n";
$data .= "--$boundary\r\n";
$data .= "Content-Disposition: form-data; name=\"users[two]\"\r\n";
$data .= "\r\n";
$data .= "second\r\n";
$data .= "--$boundary--\r\n";

$request = new ServerRequest('POST', 'http://example.com/', array(
'Content-Type' => 'multipart/form-data; boundary="' . $boundary . '"',
), $data, 1.1);

$parser = new MultipartParser();
$parsedRequest = $parser->parse($request);

$this->assertEmpty($parsedRequest->getUploadedFiles());
$this->assertSame(
array(
'users' => array(
'one' => 'single',
'two' => 'second',
),
),
$parsedRequest->getParsedBody()
);
}

public function testPostFormDataNamesWithoutQuotationMark()
{
$boundary = "---------------------------5844729766471062541057622570";

$data = "--$boundary\r\n";
$data .= "Content-Disposition: form-data; name=users[one]\r\n";
$data .= "\r\n";
$data .= "single\r\n";
$data .= "--$boundary\r\n";
$data .= "Content-Disposition: form-data; name=users[two]\r\n";
$data .= "\r\n";
$data .= "second\r\n";
$data .= "--$boundary--\r\n";

$request = new ServerRequest('POST', 'http://example.com/', array(
'Content-Type' => 'multipart/form-data; boundary="' . $boundary . '"',
), $data, 1.1);

$parser = new MultipartParser();
$parsedRequest = $parser->parse($request);

$this->assertEmpty($parsedRequest->getUploadedFiles());
$this->assertSame(
array(
'users' => array(
'one' => 'single',
'two' => 'second',
),
),
$parsedRequest->getParsedBody()
);
}

public function testPostStringOverwritesMap()
{
$boundary = "---------------------------5844729766471062541057622570";
Expand Down