diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Asset/CssViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Asset/CssViewHelper.php index 3de645353f40ee52d603d26f17687ff3eb5e6cf8..320ac8412d1f13ca56468d5ecd38327213383030 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Asset/CssViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Asset/CssViewHelper.php @@ -51,7 +51,7 @@ final class CssViewHelper extends AbstractTagBasedViewHelper * * @var bool */ - protected $escapeChildren = false; + protected $escapeChildren = true; protected AssetCollector $assetCollector; diff --git a/typo3/sysext/fluid/Tests/Functional/ViewHelpers/Asset/CssViewHelperTest.php b/typo3/sysext/fluid/Tests/Functional/ViewHelpers/Asset/CssViewHelperTest.php index be388d5a7ba9208354d930243fa336cc5eee33fd..0b2095c8df06e957485c469bdef89e5da061e8ca 100644 --- a/typo3/sysext/fluid/Tests/Functional/ViewHelpers/Asset/CssViewHelperTest.php +++ b/typo3/sysext/fluid/Tests/Functional/ViewHelpers/Asset/CssViewHelperTest.php @@ -18,6 +18,8 @@ declare(strict_types=1); namespace TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Asset; use TYPO3\CMS\Core\Page\AssetCollector; +use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Fluid\View\StandaloneView; use TYPO3\CMS\Fluid\ViewHelpers\Asset\CssViewHelper; use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; @@ -79,4 +81,76 @@ class CssViewHelperTest extends FunctionalTestCase self::assertSame($collectedJavaScripts['test']['source'], 'my.css'); self::assertSame($collectedJavaScripts['test']['attributes'], ['disabled' => 'disabled']); } + + public static function childNodeRenderingIsCorrectDataProvider(): array + { + return [ + // Double quotes + 'variable with double quotes is encoded' => [ + '</style>/* " ', // variable value + 'body { color: #{color}; }', // inner template source + 'body { color: #</style>/* " ; }', // expectation + ], + 'variable with double quotes is encoded in single quotes' => [ + '</style>/* " ', // variable value + 'body { color: \'#{color}\'; }', // inner template source + 'body { color: \'#</style>/* " \'; }', // expectation + ], + 'variable with double quotes is encoded in double quotes' => [ + '</style>/* " ', // variable value + 'body { color: "#{color}"; }', // inner template source + 'body { color: "#</style>/* " "; }', // expectation + ], + // Single quotes + 'variable with single quotes is encoded' => [ + '</style>/* \' ', // variable value + 'body { color: #{color}; }', // inner template source + 'body { color: #</style>/* ' ; }', // expectation + ], + 'variable with single quotes is encoded in single quotes' => [ + '</style>/* \' ', // variable value + 'body { color: \'#{color}\'; }', // inner template source + 'body { color: \'#</style>/* ' \'; }', // expectation + ], + 'variable with single quotes is encoded in double quotes' => [ + '</style>/* \' ', // variable value + 'body { color: "#{color}"; }', // inner template source + 'body { color: "#</style>/* ' "; }', // expectation + ], + // Raw instruction + 'raw instruction is passed' => [ + '</style>/* " ', + 'body { color: #{color -> f:format.raw()}; }', + 'body { color: #</style>/* " ; }', + ], + 'raw instruction is passed in sigle quotes' => [ + '</style>/* " ', + 'body { color: \'#{color -> f:format.raw()}\'; }', + 'body { color: \'#</style>/* " \'; }', + ], + 'raw instruction is passed in double quotes' => [ + '</style>/* " ', + 'body { color: "#{color -> f:format.raw()}"; }', + 'body { color: "#</style>/* " "; }', + ], + ]; + } + + /** + * @test + * @dataProvider childNodeRenderingIsCorrectDataProvider + */ + public function childNodeRenderingIsCorrect(string $value, string $source, string $expectation): void + { + $assetCollector = new AssetCollector(); + GeneralUtility::setSingletonInstance(AssetCollector::class, $assetCollector); + + $view = new StandaloneView(); + $view->setTemplateSource(sprintf('<f:asset.css identifier="test">%s</f:asset.css>', $source)); + $view->assign('color', $value); + $view->render(); + GeneralUtility::removeSingletonInstance(AssetCollector::class, $assetCollector); + + self::assertSame($expectation, $assetCollector->getInlineStyleSheets()['test']['source']); + } }