Skip to content

Commit ef03b6d

Browse files
Don't rely on Request::getPayload() to populate the parsed body
1 parent 3c62b81 commit ef03b6d

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

Factory/PsrHttpFactory.php

Lines 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

Lines 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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy