From 459624590e7d2e39ce760c8da38c00cc35dc32a5 Mon Sep 17 00:00:00 2001 From: Mathias Bolt Lesniak Date: Sun, 27 Aug 2023 19:14:12 +1200 Subject: [PATCH] [BUGFIX] Correct type check for stream resource The constructor of `\TYPO3\CMS\Core\Http\Request` now correctly accepts resources of the type "stream" as $body argument. Resolves: #101764 Related: #97620 Releases: main, 12.4 Change-Id: I2e7000c11ef4a16334f3305142ef8fb7fe6c639f Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/80710 Reviewed-by: Christian Kuhn Tested-by: core-ci Tested-by: Christian Kuhn --- typo3/sysext/core/Classes/Http/Request.php | 2 +- .../core/Tests/Unit/Http/RequestTest.php | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/typo3/sysext/core/Classes/Http/Request.php b/typo3/sysext/core/Classes/Http/Request.php index 47ac172bacf9..09f13dc81c22 100644 --- a/typo3/sysext/core/Classes/Http/Request.php +++ b/typo3/sysext/core/Classes/Http/Request.php @@ -96,7 +96,7 @@ public function __construct(UriInterface|string|null $uri = null, string $method $this->body = $body; } else { $this->body = match (get_debug_type($body)) { - 'string', 'resource' => new Stream($body), + 'string', 'resource (stream)' => new Stream($body), 'null' => null, default => throw new \InvalidArgumentException('Body must be a string stream resource identifier, a stream resource, or a StreamInterface instance', 1436717271), }; diff --git a/typo3/sysext/core/Tests/Unit/Http/RequestTest.php b/typo3/sysext/core/Tests/Unit/Http/RequestTest.php index aabe93cedc2e..26a85b168f1f 100644 --- a/typo3/sysext/core/Tests/Unit/Http/RequestTest.php +++ b/typo3/sysext/core/Tests/Unit/Http/RequestTest.php @@ -17,6 +17,7 @@ namespace TYPO3\CMS\Core\Tests\Unit\Http; +use Psr\Http\Message\StreamInterface; use TYPO3\CMS\Core\Http\Request; use TYPO3\CMS\Core\Http\Stream; use TYPO3\CMS\Core\Http\Uri; @@ -128,6 +129,26 @@ public function constructorRaisesExceptionForInvalidBody($body): void new Request(null, 'GET', $body); } + public static function validRequestBodyDataProvider(): array + { + return [ + 'stringResourceIdentifier' => ['php://input'], + 'streamResource' => [fopen('php://memory', 'r')], + 'streamInterface' => [new Stream(fopen('php://memory', 'r'))], + 'null' => [null], + ]; + } + + /** + * @param resource|StreamInterface|string|null $body + * @dataProvider validRequestBodyDataProvider + * @test + */ + public function constructorDoesNotRaiseExceptionForValidBody($body): void + { + new Request(null, 'GET', $body); + } + /** * @test */