Skip to content

Commit 55deebc

Browse files
authored
[9.x] Back porting #47838 (#47840)
* Retain $request->request InputBag type * Assert content
1 parent 6517f5d commit 55deebc

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/Illuminate/Http/Request.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Illuminate\Support\Traits\Macroable;
1212
use RuntimeException;
1313
use Symfony\Component\HttpFoundation\Exception\SessionNotFoundException;
14+
use Symfony\Component\HttpFoundation\InputBag;
1415
use Symfony\Component\HttpFoundation\ParameterBag;
1516
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
1617
use Symfony\Component\HttpFoundation\Session\SessionInterface;
@@ -487,7 +488,7 @@ public static function createFromBase(SymfonyRequest $request)
487488
$newRequest->content = $request->content;
488489

489490
if ($newRequest->isJson()) {
490-
$newRequest->request = $newRequest->json();
491+
$newRequest->request = new InputBag($newRequest->json()->all());
491492
}
492493

493494
return $newRequest;

tests/Http/HttpRequestTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use RuntimeException;
1717
use Symfony\Component\HttpFoundation\Exception\SessionNotFoundException;
1818
use Symfony\Component\HttpFoundation\File\UploadedFile as SymfonyUploadedFile;
19+
use Symfony\Component\HttpFoundation\InputBag;
1920
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
2021
use Symfony\Component\HttpFoundation\Session\SessionInterface;
2122

@@ -1559,4 +1560,18 @@ public function testHttpRequestFlashExceptCallsFlashWithProperParameters()
15591560
$request->setLaravelSession($session);
15601561
$request->flashExcept(['email']);
15611562
}
1563+
1564+
public function testGeneratingJsonRequestFromParentRequestUsesCorrectType()
1565+
{
1566+
if (! method_exists(SymfonyRequest::class, 'getPayload')) {
1567+
return;
1568+
}
1569+
1570+
$base = SymfonyRequest::create('/', 'POST', server: ['CONTENT_TYPE' => 'application/json'], content: '{"hello":"world"}');
1571+
1572+
$request = Request::createFromBase($base);
1573+
1574+
$this->assertInstanceOf(InputBag::class, $request->getPayload());
1575+
$this->assertSame('world', $request->getPayload()->get('hello'));
1576+
}
15621577
}

0 commit comments

Comments
 (0)