Commit fff0380e authored by Oliver Hader's avatar Oliver Hader Committed by Benni Mack
Browse files

[BUGFIX] Handle empty fragments in HtmlWorker and f:transform.html

HtmlWorker (triggered by f:transform.html view helper) issued a PHP
warning concering an empty Document Fragment when the markup to be
parsed is an empty string (`''`).

Resolves: #95867
Releases: master
Change-Id: I9018274d9f16b20550a8ac5b740753e33737b867
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/72210


Tested-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
parent aba3d452
......@@ -110,7 +110,7 @@ class HtmlViewHelper extends AbstractViewHelper
$onFailureFlags = self::MAP_ON_FAILURE[$onFailure] ?? HtmlWorker::REMOVE_ENCLOSURE_ON_FAILURE;
return (string)$worker
->parse($content)
->parse((string)$content)
->transformUri($selector, $onFailureFlags);
}
}
......@@ -50,6 +50,10 @@ class HtmlViewHelperTest extends FunctionalTestCase
public static function isTransformedDataProvider(): array
{
return [
'empty string' => [
'',
'',
],
'any HTML tag' => [
'<p>value a</p><p>value b</p>',
'<p>value a</p><p>value b</p>',
......
......@@ -177,7 +177,9 @@ class HtmlWorker
$document = $fragment->ownerDocument;
$mount = $document->createElement('div');
$document->appendChild($mount);
$mount->appendChild($fragment);
if ($fragment->hasChildNodes()) {
$mount->appendChild($fragment);
}
return $mount;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment