Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6410dda

Browse filesBrowse files
committed
bug #122 Don't rely on Request::getPayload() to populate the parsed body (nicolas-grekas)
This PR was merged into the 2.3 branch. Discussion ---------- Don't rely on Request::getPayload() to populate the parsed body That's just not needed and creates issues like #121 + fixes a bug with invalid jsons. Commits ------- ef03b6d Don't rely on Request::getPayload() to populate the parsed body
2 parents 3c62b81 + ef03b6d commit 6410dda
Copy full SHA for 6410dda

File tree

2 files changed

+6
-7
lines changed
Filter options

2 files changed

+6
-7
lines changed

‎Factory/PsrHttpFactory.php

Copy file name to clipboardExpand all lines: Factory/PsrHttpFactory.php
+5-6Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
use Psr\Http\Message\UploadedFileInterface;
2121
use Symfony\Bridge\PsrHttpMessage\HttpMessageFactoryInterface;
2222
use Symfony\Component\HttpFoundation\BinaryFileResponse;
23-
use Symfony\Component\HttpFoundation\Exception\JsonException;
2423
use Symfony\Component\HttpFoundation\File\UploadedFile;
2524
use Symfony\Component\HttpFoundation\Request;
2625
use Symfony\Component\HttpFoundation\Response;
@@ -79,11 +78,11 @@ public function createRequest(Request $symfonyRequest)
7978
$format = $symfonyRequest->getContentType();
8079
}
8180

82-
if (method_exists(Request::class, 'getPayload') && 'json' === $format) {
83-
try {
84-
$parsedBody = $symfonyRequest->getPayload()->all();
85-
} catch (JsonException $e) {
86-
$parsedBody = [];
81+
if ('json' === $format) {
82+
$parsedBody = json_decode($symfonyRequest->getContent(), true, 512, \JSON_BIGINT_AS_STRING);
83+
84+
if (!\is_array($parsedBody)) {
85+
$parsedBody = null;
8786
}
8887
} else {
8988
$parsedBody = $symfonyRequest->request->all();

‎Tests/Factory/PsrHttpFactoryTest.php

Copy file name to clipboardExpand all lines: Tests/Factory/PsrHttpFactoryTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,6 @@ public function testWrongJsonContent()
293293
$request = new Request([], [], [], [], [], $headers, '{"city":"Paris"');
294294
$psrRequest = $this->factory->createRequest($request);
295295

296-
$this->assertSame([], $psrRequest->getParsedBody());
296+
$this->assertNull($psrRequest->getParsedBody());
297297
}
298298
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.