Bug #103085
closedDeprecation strip_tags in stdWrap_stripHtml Passing null to parameter #1
100%
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
Updated by Franz Holzinger 12 months ago
· Edited
Solution:
public function stdWrap_stripHtml($content = '') { return !empty($content) ? strip_tags($content) : ''; }
Updated by Andreas Kienast 12 months ago
· Edited
- Status changed from New to Needs Feedback
Thank you. Can you by chance provide a strack trace, please?
Updated by Franz Holzinger 12 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; } }
Updated by Andreas Kienast 12 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?
Updated by Franz Holzinger 12 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.
Updated by Benni Mack 12 months ago
Hey Franz,
can you share your TypoScript which is executed and causes the problem?
Updated by Franz Holzinger 12 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.
Updated by Benni Mack 12 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?
Updated by Franz Holzinger 12 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.
Updated by Stefan Bürk 12 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.
Updated by Franz Holzinger 11 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
}
}
Updated by Gerrit Code Review 8 months ago
- Status changed from Needs Feedback to Under Review
Patch set 1 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/84446
Updated by Georg Ringer 8 months ago
had this also multiple times with updates and htmlSpecialChars calls
Updated by Gerrit Code Review 8 months ago
Patch set 1 for branch 12.4 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/84458
Updated by Georg Ringer 8 months ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset ad4c39b020b52e3a491c6c8d0bb5cecd8febf8da.