Skip to content

Commit

Permalink
[BUGFIX] Concatenate inline JavaScript with line break
Browse files Browse the repository at this point in the history
This adds a line break between concatenated "inline" JavaScripts
in order to keep JavaScript without trailing ';' valid.

Resolves: #99503
Releases: main, 12.4, 11.5
Change-Id: Icf902679c715687c5be2e5f572526608ce31f882
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/81686
Reviewed-by: Benjamin Franzke <ben@bnf.dev>
Tested-by: core-ci <typo3@b13.com>
Tested-by: Benjamin Franzke <ben@bnf.dev>
  • Loading branch information
jonaseberle authored and bnf committed Nov 6, 2023
1 parent f6fe266 commit 08c6714
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
Expand Up @@ -687,19 +687,30 @@ public function setCurrentVal($value)
*/
public function cObjGet($setup, $addKey = '')
{
if (!is_array($setup)) {
return '';
return implode('', $this->cObjGetSeparated($setup, $addKey));
}

/**
* Rendering of a "numerical array" of cObjects from TypoScript
* Will call ->cObjGetSingle() for each cObject found.
*
* @return list<string>
*/
public function cObjGetSeparated(?array $setup, string $addKey = ''): array
{
if (!is_array($setup) || $setup === []) {
return [];
}
$sKeyArray = ArrayUtility::filterAndSortByNumericKeys($setup);
$content = '';
$contentObjects = [];
foreach ($sKeyArray as $theKey) {
$theValue = $setup[$theKey];
if ((int)$theKey && !str_contains($theKey, '.')) {
$conf = $setup[$theKey . '.'] ?? [];
$content .= $this->cObjGetSingle($theValue, $conf, $addKey . $theKey);
$contentObjects[] = $this->cObjGetSingle($theValue, $conf, $addKey . $theKey);
}
}
return $content;
return $contentObjects;
}

/**
Expand Down
16 changes: 14 additions & 2 deletions typo3/sysext/frontend/Classes/Http/RequestHandler.php
Expand Up @@ -716,9 +716,21 @@ protected function processHtmlBasedRenderingSettings(TypoScriptFrontendControlle
);

// Javascript inline code
$inlineJS = $controller->cObj->cObjGet($controller->pSetup['jsInline.'] ?? null, 'jsInline.');
$inlineJS = implode(
LF,
$controller->cObj->cObjGetSeparated(
$controller->pSetup['jsInline.'] ?? null,
'jsInline.'
)
);
// Javascript inline code for Footer
$inlineFooterJs = $controller->cObj->cObjGet($controller->pSetup['jsFooterInline.'] ?? null, 'jsFooterInline.');
$inlineFooterJs = implode(
LF,
$controller->cObj->cObjGetSeparated(
$controller->pSetup['jsFooterInline.'] ?? null,
'jsFooterInline.'
)
);
$compressJs = (bool)($controller->config['config']['compressJs'] ?? false);

// Needs to be called after call cObjGet() calls in order to get all headerData and footerData and replacements
Expand Down
4 changes: 4 additions & 0 deletions typo3/sysext/frontend/Tests/Unit/Http/RequestHandlerTest.php
Expand Up @@ -241,6 +241,7 @@ public function generateMetaTagExpectExceptionOnBogusTags(): void
$siteLanguage = $this->createSiteWithLanguage()->getLanguageById(3);
$cObj = $this->prophesize(ContentObjectRenderer::class);
$cObj->cObjGet(Argument::cetera())->shouldBeCalled();
$cObj->cObjGetSeparated(Argument::cetera())->willReturn([]);
$cObj->stdWrap(Argument::cetera())->willReturn($stdWrapResult);
$tmpl = $this->prophesize(TemplateService::class);
$frontendControllerProphecy = $this->prophesize(TypoScriptFrontendController::class);
Expand Down Expand Up @@ -284,6 +285,7 @@ public function generateMetaTagHtmlGeneratesCorrectTags(array $typoScript, strin
$siteLanguage = $this->createSiteWithLanguage()->getLanguageById(3);
$cObj = $this->prophesize(ContentObjectRenderer::class);
$cObj->cObjGet(Argument::cetera())->shouldBeCalled();
$cObj->cObjGetSeparated(Argument::cetera())->willReturn([]);
$cObj->stdWrap(Argument::cetera())->willReturn($stdWrapResult);
$tmpl = $this->prophesize(TemplateService::class);
$frontendControllerProphecy = $this->prophesize(TypoScriptFrontendController::class);
Expand Down Expand Up @@ -332,6 +334,7 @@ public function generateMetaTagHtmlGenerateNoTagWithEmptyContent(): void
$siteLanguage = $this->createSiteWithLanguage()->getLanguageById(3);
$cObj = $this->prophesize(ContentObjectRenderer::class);
$cObj->cObjGet(Argument::cetera())->shouldBeCalled();
$cObj->cObjGetSeparated(Argument::cetera())->willReturn([]);
$cObj->stdWrap(Argument::cetera())->willReturn($stdWrapResult);
$tmpl = $this->prophesize(TemplateService::class);
$frontendControllerProphecy = $this->prophesize(TypoScriptFrontendController::class);
Expand Down Expand Up @@ -435,6 +438,7 @@ public function generateMultipleMetaTags(array $typoScript, string $stdWrapResul
$siteLanguage = $this->createSiteWithLanguage()->getLanguageById(3);
$cObj = $this->prophesize(ContentObjectRenderer::class);
$cObj->cObjGet(Argument::cetera())->shouldBeCalled();
$cObj->cObjGetSeparated(Argument::cetera())->willReturn([]);
$cObj->stdWrap(Argument::cetera())->willReturn($stdWrapResult);
$tmpl = $this->prophesize(TemplateService::class);
$frontendControllerProphecy = $this->prophesize(TypoScriptFrontendController::class);
Expand Down

0 comments on commit 08c6714

Please sign in to comment.