Project

General

Profile

Actions

Bug #101764

closed

Invalid type check for resource in \TYPO3\CMS\Core\Http\Request

Added by Mathias Bolt Lesniak about 1 year ago. Updated 5 months ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
-
Target version:
-
Start date:
2023-08-27
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
12
PHP Version:
Tags:
Complexity:
easy
Is Regression:
Sprint Focus:

Description

The constructor of the Request class is supposed to accept a $body of the type "string|resource|StreamInterface|null". However, it does not accept a "resource" because it tests for the wrong string from `get_debug_type($body)`.

            $this->body = match (get_debug_type($body)) {
                'string', 'resource' => 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),
            };

According to the PHP documentation `get_debug_type()` will never return just the string "resource". It will instead return "resource (resourcename)" (e.g. "resource (stream)") or "resource (closed)". https://www.php.net/manual/en/function.get-debug-type.php#refsect1-function.get-debug-type-returnvalues

Since the returned string changes depending on the type of resource, it is not possible to predict exactly. This means `get_debug_type()` and `match` cannot be used to test for a resource, as `match` relies on an exact string.

The implementation in TYPO3 v11 works correctly. It is implemented a bit different, but correctly uses `is_resource(‪$body)`.


Related issues 1 (0 open1 closed)

Related to TYPO3 Core - Bug #97620: PSR-7 compat fixes for core RequestClosedLarry Garfield2022-05-12

Actions
Actions

Also available in: Atom PDF