Skip to content

Commit 487efcd

Browse files
author
Jeremiah VALERIE
committed
No empty body accepted for json request parser
1 parent 404feba commit 487efcd

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

Request/Parser.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ private function getParsedBody(Request $request)
5050

5151
// JSON object
5252
case static::CONTENT_TYPE_JSON:
53+
if (empty($body)) {
54+
throw new BadRequestHttpException('The request content body must not be empty when using json content type request.');
55+
}
56+
5357
$parsedBody = json_decode($body, true);
5458

5559
if (JSON_ERROR_NONE !== json_last_error()) {

Tests/Functional/Controller/GraphControllerTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,18 @@ public function testEndpointWithEmptyQuery()
9595
$client->getResponse()->getContent();
9696
}
9797

98+
/**
99+
* @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
100+
* @expectedExceptionMessage The request content body must not be empty when using json content type request.
101+
*/
102+
public function testEndpointWithEmptyJsonBodyQuery()
103+
{
104+
$client = static::createClient();
105+
$client->request('GET', '/', [], [], ['CONTENT_TYPE' => 'application/json']);
106+
$client->getResponse()->getContent();
107+
}
108+
109+
98110
/**
99111
* @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
100112
* @expectedExceptionMessage POST body sent invalid JSON

0 commit comments

Comments
 (0)