Skip to content

Commit

Permalink
[BUGFIX] Correct type check for stream resource
Browse files Browse the repository at this point in the history
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 <lolli@schwarzbu.ch>
Tested-by: core-ci <typo3@b13.com>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
  • Loading branch information
mabolek authored and lolli42 committed Aug 28, 2023
1 parent 9778ef0 commit 4596245
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion typo3/sysext/core/Classes/Http/Request.php
Expand Up @@ -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),
};
Expand Down
21 changes: 21 additions & 0 deletions typo3/sysext/core/Tests/Unit/Http/RequestTest.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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
*/
Expand Down

0 comments on commit 4596245

Please sign in to comment.