Project

General

Profile

Actions

Bug #103085

open

Deprecation strip_tags in stdWrap_stripHtml Passing null to parameter #1

Added by Franz Holzinger 2 months ago. Updated 2 months ago.

Status:
Needs Feedback
Priority:
Should have
Assignee:
-
Category:
Frontend
Target version:
-
Start date:
2024-02-08
Due date:
% Done:

0%

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

Description

TYPO3 core raises a deprecation notice:

(1/1) #1476107295 TYPO3\CMS\Core\Error\Exception
PHP Runtime Deprecation Notice: strip_tags(): Passing null to parameter #1 ($string) of type string is deprecated in /home/users/myuser/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php line 2033

at strip_tags()
in /home/users/myuser/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php line 2033


     * @return string The processed input value
     */
    public function stdWrap_stripHtml($content = '')
    {
        return strip_tags($content);
    }


Files

fehler-103085-strip_tags.txt (45.7 KB) fehler-103085-strip_tags.txt Franz Holzinger, 2024-02-09 08:06
Actions #1

Updated by Franz Holzinger 2 months ago · Edited

Solution:

    public function stdWrap_stripHtml($content = '')
    {
        return !empty($content) ? strip_tags($content) : '';
    }
Actions #2

Updated by Andreas Kienast 2 months ago · Edited

  • Status changed from New to Needs Feedback

Thank you. Can you by chance provide a strack trace, please?

Actions #3

Updated by Franz Holzinger 2 months ago

See the attached file for the full backtrace.

at TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer->stdWrap_stripHtml()
in /home/users/myuser/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php line 1234
                    $isExecuted[$functionName] = true;
                    $isExecuted[$functionProperties] = true;
                    // Call the function with the prefix stdWrap_ to make sure nobody can execute functions just by adding their name to the TS Array
                    $functionName = 'stdWrap_' . $functionName;
                    $content = $this->{$functionName}($content, $singleConf);
                } elseif ($functionType === 'boolean' && !($conf[$functionName] ?? null)) {
                    $isExecuted[$functionName] = true;
                    $isExecuted[$functionProperties] = true;
                }
at TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer->stdWrap()
in /home/users/myuser/typo3/sysext/frontend/Classes/ContentObject/TextContentObject.php line 44
            $content = $this->cObj->stdWrap($content, $conf['value.']);
            unset($conf['value.']);
        }
        if (!empty($conf)) {
            $content = $this->cObj->stdWrap($content, $conf);
        }
        return $content;
    }
}

Actions #4

Updated by Andreas Kienast 2 months ago

Thanks for the strack trace. According to it, the offending method is called by ContentObjectRenderer->stdWrap(), which casts the input data to a string. Can you please provide more information how to reproduce this issue in a current v12?

Actions #5

Updated by Franz Holzinger 2 months ago

See the complete backtrace file. There is a call from fh_debug. Maybe you can reproduce it by activating this extension.

at TYPO3\CMS\Frontend\Http\RequestHandler->handle()
in /home/users/myuser/typo3conf/ext/fh_debug/Classes/Middleware/Bootstrap.php line 45

{
$api = GeneralUtility::makeInstance(BootstrapApi::class);
$api->init($request);
return $handler->handle($request);
}

However this extension replaces one file in TYYPO3: fh_debug/Patches/TYPO3/sysext/core/Resources/PHP/GlobalDebugFunctions.php
This must be replaced manually. And a debug line must be inserted into the PHP code. Then this should be reproducable.

Actions #6

Updated by Benni Mack 2 months ago

Hey Franz,

can you share your TypoScript which is executed and causes the problem?

Actions #7

Updated by Franz Holzinger 2 months ago

I think there is no TypoScript involved.
It is just the Middleware to initialze everything for the extension.

class Bootstrap implements MiddlewareInterface
{
/** * Hook to initialze the error object * * @param ServerRequestInterface $request * @param RequestHandlerInterface $handler * @return ResponseInterface
*/
        public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
        {
            $api = GeneralUtility::makeInstance(BootstrapApi::class);
            $api->init($request);

            return $handler->handle($request);
        }
    }

Then the hander method is executed by TYPO3. I do not know what exactly it does there.

Actions #8

Updated by Benni Mack 2 months ago

Hey Franz,

Franz Holzinger wrote in #note-7:

Then the hander method is executed by TYPO3. I do not know what exactly it does there.

$api = GeneralUtility::makeInstance(BootstrapApi::class);
$api->init($request);

This code does not seem to be TYPO3 Core API?

Actions #9

Updated by Franz Holzinger 2 months ago

This is the initialization code for the extension fh_debug.
TYPO3 requires that no such code should be in the file ext_localconf.php any more.

Actions #10

Updated by Stefan Bürk 2 months ago

Benni Mack: can you share your TypoScript which is executed and causes the problem?
Franz Holzinger: I think there is no TypoScript involved.

Please provide kind of TypoScript. ContentObjectRendere deals with rendering configuration, literlly `TypoScript`. So TypoScript is relevent to understand in which constellation through the call chain it ends up calling `ContentObjectRenderer::stdWrap_stripHtml()`.

Given the call chain there must be some

lib.someThing = TEXT
# ....

involved with stdWrap definitions at some point.

Last place calling the `ContentObjectRenderer::stdWrap_stripHtml? is the L1234 in that class:

                    
// Call the function with the prefix stdWrap_ to make sure nobody can execute functions just by adding their name to the TS Array
$functionName = 'stdWrap_' . $functionName;
$content = $this->{$functionName}($content, $singleConf); // <--- this is the call to stdWrap_stripHtml

which is prepared some lines above with null fallbacks for the method name and config

// Get just that part of $conf that is needed for the particular function
$singleConf = [
  $functionName => $conf[$functionName] ?? null,
  $functionProperties => $conf[$functionProperties] ?? null,
];

As a loop is here involved, overriding $content with method call it may be another call beforehand to a stdWrap function returning `null` and than leading to this case.

As this is a tricky part, getting some TypoScript to reproduce this would be nice - not ruleing out the named extension or now.

What happens if you uninstall the extension ?

So, at beast add a xdebug breakpoint and on a exception look into the variables provided and go up to find the "typoscript" part leading to this issue.

Actions #11

Updated by Franz Holzinger 2 months ago

Here is the TypoScript which leads to the Runtime Exception:

renderObj = COA
renderObj {
10 = TEXT
10 {
field = bodytext
stripHtml = 1
crop = 160 | ... | 1
}
}

The error happens when the bodytext is an empty string.

Here is the full part:

page = PAGE
page {
...
meta {
keywords.field = keywords
keywords.ifEmpty = {$defaultkeywords}
description.field = description # description.ifEmpty = {$defaultdescription}
description.ifEmpty.stdWrap.cObject = CONTENT
description.ifEmpty.stdWrap.cObject {
table = tt_content
select {
selectFields = bodytext
max = 1
}
renderObj = COA
renderObj {
10 = TEXT
10 {
field = bodytext
stripHtml = 1
crop = 160 | ... | 1
}
}
}
robots = index,follow
google-site-verification = xxx
p:domain_verify = xxx
viewport = width=device-width, initial-scale=1.0
format-detection = telephone=no
}
}
Actions

Also available in: Atom PDF