Bug #91533
closedTypeError in Frontend Http RequestHandler::generateMetaTagHtml - trim() expects parameter 1 to be string
100%
Description
System¶
- TYPO3-Version: 9.5.18
- Webserver: Apache
- PHP-Version: 7.2.31
- Database (Default): MySQL 5.5.5-10.0.38-MariaDB
- Application-Context: Development
- Composer-Mode: activated
- Operating System: Linux 3.10.0-693.11.6.el7.x86_64
How to reproduce¶
TS-setup:
lib.teaserMediaReference = FILES
lib.teaserMediaReference {
references {
data = levelmedia:-1, slide
treatIdAsReference = 1
}
begin = 0
maxItems = 1
renderObj = IMG_RESOURCE
renderObj.file {
import.data = file:current:uid
treatIdAsReference = 1
width = 751m
height = 752m
minWidth = 200
minHeight = 200
}
}
page.meta {
og:image.stdWrap.cObject < lib.teaserMediaReference
og:image.stdWrap.wrap = {$protocol}://{$siteurl}/|
og:image.attribute = property
og:image:width.stdWrap.data = TSFE:lastImgResourceInfo|0
og:image:width.attribute = property
og:image:height.stdWrap.data = TSFE:lastImgResourceInfo|1
og:image:height.attribute = property
}
TYPO3 Exception¶
(1/1) TypeError:
trim() expects parameter 1 to be string, integer given
in public/typo3/sysext/frontend/Classes/Http/RequestHandler.php line 1039
TYPO3 9: https://api.typo3.org/9.5/frontend_2_classes_2_http_2_request_handler_8php_source.html#l01039
TYPO3 10: https://api.typo3.org/master/frontend_2_classes_2_http_2_request_handler_8php_source.html#l00930
$value = trim($cObj->stdWrap($nodeValue, $metaTagTypoScript[$key . '.']) ?? '');
at trim(751)
in public/typo3/sysext/frontend/Classes/Http/RequestHandler.php line 1039
$value = trim($cObj->stdWrap($nodeValue, $metaTagTypoScript[$key . '.']) ?? '');
at TYPO3\CMS\Frontend\Http\RequestHandler->generateMetaTagHtml(
array(
[...]
'og:image.' => array(
'stdWrap.' => array(
'cObject' => 'FILES',
'cObject.' => array(
'references.' => array(
'data' => 'levelmedia:-1, slide',
'treatIdAsReference' => '1'
),
'begin' => '0',
'maxItems' => '1',
'renderObj' => 'IMG_RESOURCE',
'renderObj.' => array(
'file.' => array(
'import.' => array(
'data' => 'file:current:uid'
),
'treatIdAsReference' => '1',
'width' => '751m',
'height' => '752m',
'minWidth' => '200',
'minHeight' => '200'
)
)
),
'wrap' => 'https://example.org/|'
),
'attribute' => 'property'
),
'og:image:width.' => array(
'stdWrap.' => array(
'data' => 'TSFE:lastImgResourceInfo|0'
),
'attribute' => 'property'
),
'og:image:height.' => array(
'stdWrap.' => array(
'data' => 'TSFE:lastImgResourceInfo|1'
),
'attribute' => 'property'
)
),
object(TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer)
)
in public/typo3/sysext/frontend/Classes/Http/RequestHandler.php line 774
$this->generateMetaTagHtml(
$controller->pSetup['meta.'] ?? [],
$controller->cObj
);
Probable fix¶
TYPO3 9: https://api.typo3.org/9.5/frontend_2_classes_2_http_2_request_handler_8php_source.html#l01039
TYPO3 10: https://api.typo3.org/master/frontend_2_classes_2_http_2_request_handler_8php_source.html#l00930
Change
$nodeValue = $properties['_typoScriptNodeValue'] ?? '';
$value = trim($cObj->stdWrap($nodeValue, $metaTagTypoScript[$key . '.']) ?? '');
if ($value === '' && !empty($properties['value'])) {
$value = $properties['value'];
$replace = false;
}
to
$nodeValue = $properties['_typoScriptNodeValue'] ?? '';
$nodeValueStdWrapped = $cObj->stdWrap($nodeValue, $metaTagTypoScript[$key . '.']);
$value = is_string($nodeValueStdWrapped) ? trim($nodeValueStdWrapped) : '';
if ($value === '' && !empty($properties['value'])) {
$value = $properties['value'];
$replace = false;
}
Maybe the underlying problem actually is that the values of width and height get typecastet to integer instead of string and the error is found in a totally different place.
See TS-setup:
lib.teaserMediaReference = FILES
lib.teaserMediaReference {
[...]
renderObj = IMG_RESOURCE
renderObj.file {
[...]
width = 751m
height = 752m
[...]
}
}
page.meta {
og:image.stdWrap.cObject < lib.teaserMediaReference
og:image.stdWrap.wrap = {$protocol}://{$siteurl}/|
og:image.attribute = property
[...]
}