From e0f94d6e9b9c822c824c0b38986fc519057b574a Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Wed, 26 Jul 2023 10:50:55 +1000 Subject: [PATCH] Retain $request->request InputBag type --- src/Illuminate/Http/Request.php | 3 ++- tests/Http/HttpRequestTest.php | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Http/Request.php b/src/Illuminate/Http/Request.php index a0255fc898eb..2da2efd95d16 100644 --- a/src/Illuminate/Http/Request.php +++ b/src/Illuminate/Http/Request.php @@ -11,6 +11,7 @@ use Illuminate\Support\Traits\Macroable; use RuntimeException; use Symfony\Component\HttpFoundation\Exception\SessionNotFoundException; +use Symfony\Component\HttpFoundation\InputBag; use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\Request as SymfonyRequest; use Symfony\Component\HttpFoundation\Session\SessionInterface; @@ -487,7 +488,7 @@ public static function createFromBase(SymfonyRequest $request) $newRequest->content = $request->content; if ($newRequest->isJson()) { - $newRequest->request = $newRequest->json(); + $newRequest->request = new InputBag($newRequest->json()->all()); } return $newRequest; diff --git a/tests/Http/HttpRequestTest.php b/tests/Http/HttpRequestTest.php index df08d5b941f8..40fd9431d746 100644 --- a/tests/Http/HttpRequestTest.php +++ b/tests/Http/HttpRequestTest.php @@ -16,6 +16,7 @@ use RuntimeException; use Symfony\Component\HttpFoundation\Exception\SessionNotFoundException; use Symfony\Component\HttpFoundation\File\UploadedFile as SymfonyUploadedFile; +use Symfony\Component\HttpFoundation\InputBag; use Symfony\Component\HttpFoundation\Request as SymfonyRequest; use Symfony\Component\HttpFoundation\Session\SessionInterface; @@ -1556,4 +1557,17 @@ public function testHttpRequestFlashExceptCallsFlashWithProperParameters() $request->setLaravelSession($session); $request->flashExcept(['email']); } + + public function testGeneratingJsonRequestFromParentRequestUsesCorrectType() + { + if (! method_exists(SymfonyRequest::class, 'getPayload')) { + return; + } + + $base = SymfonyRequest::create('/', 'POST', server: ['CONTENT_TYPE' => 'application/json'], content: '{"hello":"world"}'); + + $request = Request::createFromBase($base); + + $this->assertInstanceOf(InputBag::class, $request->getPayload()); + } }