Skip to content

Commit

Permalink
[BUGFIX] Prevent TypeError in AssetCollector related ViewHelpers
Browse files Browse the repository at this point in the history
The two new ViewHelpers `CssViewHelper` and `ScriptViewHelper`
automatically render the content of their body if no source file
is supplied in the ViewHelpers argument. However if the body is
empty, NULL is passed to the AssetCollectors add inline code functions.
This leads to a TypeError as these parameters are type hinted.

Therefore the body content is now checked before
the methods get called to prevent passing NULL or an empty string.

Resolves: #90539
Releases: master
Change-Id: I80feb9551f50e6ab8ac56740b605c4bbbfbe3069
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/63437
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Jens Ulrich <jens.ulrich@snk.de>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Susanne Moog <look@susi.dev>
Tested-by: Daniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Jens Ulrich <jens.ulrich@snk.de>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Susanne Moog <look@susi.dev>
Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de>
  • Loading branch information
o-ba authored and susannemoog committed Feb 26, 2020
1 parent 675666b commit 6f186ff
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Expand Up @@ -94,7 +94,10 @@ public function render(): string
if ($file !== null) {
$this->assetCollector->addStyleSheet($identifier, $file, $attributes, $options);
} else {
$this->assetCollector->addInlineStyleSheet($identifier, $this->renderChildren(), $attributes, $options);
$content = (string)$this->renderChildren();
if ($content !== '') {
$this->assetCollector->addInlineStyleSheet($identifier, $content, $attributes, $options);
}
}
return '';
}
Expand Down
Expand Up @@ -90,7 +90,10 @@ public function render(): string
if ($src !== null) {
$this->assetCollector->addJavaScript($identifier, $src, $attributes, $options);
} else {
$this->assetCollector->addInlineJavaScript($identifier, $this->renderChildren(), $attributes, $options);
$content = (string)$this->renderChildren();
if ($content !== '') {
$this->assetCollector->addInlineJavaScript($identifier, $content, $attributes, $options);
}
}
return '';
}
Expand Down

0 comments on commit 6f186ff

Please sign in to comment.