Skip to content

Commit 9d2a074

Browse files
authored
Merge pull request #363 from ebimmel/server-requst-body-empty-when-request-from-dot-net-app
Server requst body empty when request from dot net app
2 parents 248202e + f07a923 commit 9d2a074

2 files changed

Lines changed: 68 additions & 2 deletions

File tree

src/Io/MultipartParser.php

Lines changed: 2 additions & 2 deletions
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

@@ -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: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,72 @@ 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+
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+
69135
public function testPostStringOverwritesMap()
70136
{
71137
$boundary = "---------------------------5844729766471062541057622570";

0 commit comments

Comments
 (0)