Bug #99503
closed
Inline script concatenation requires scripts to have trailing ";"
Added by Jonas Eberle almost 2 years ago.
Updated 5 months ago.
Description
concatenateJs produces invalid JavaScript if scripts do not end with ';'.
In JavaScript ';' line endings are optional, but when concatenating scripts a ';' (or a line feed) needs to be added.
Minimum reproducible example:
(TypoScript settings)
config.concatenateJs = 1
page.jsInline {
script1 = TEXT
script1.value = alert(1)
script2 = TEXT
script2.value = alert(2)
}
This results in
alert(1)alert(2)
(This applies to concatenated files in any of the PAGE.includeJS functions and friends, too)
Correction: it seems string keys are not possible there.
So the MRE is:
config.concatenateJs = 1
page.jsInline {
10 = TEXT
10.value = alert(1)
20 = TEXT
20.value = alert(2)
}
My debugging went as far as to understand that page.jsInline is quite different from the others like page.includeJS.
page.jsInline renders no separators because it gets handed to \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::cObjGet directly.
- Status changed from New to Under Review
- Subject changed from config.concatenateJs requires scripts to finish with ";" to Inline script concatenation requires scripts to have trailing ";"
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Please reopen, because applied patch makes unnecessary BC at least on 11.5.
See:
public function cObjGet($setup, $addKey = '')
{
return implode('', $this->cObjGetSeparated($setup, $addKey));
}
public function cObjGetSeparated(?array $setup, string $addKey = ''): array
{
if (!is_array($setup) || $setup === []) {
return [];
}
Proposal:
public function cObjGet($setup, $addKey = '')
{
if (!is_array($setup)) {
return '';
}
return implode('', $this->cObjGetSeparated($setup, $addKey));
}
public function cObjGetSeparated(?array $setup = [], string $addKey = ''): array
{
if (empty($setup)) {
return [];
}
Do you mean it became stricter? I agree, and I am sorry I have not noticed that. Before, it would return '' when given anything but an array.
Sorry, what is "BC"?
- Status changed from Resolved to Closed
Also available in: Atom
PDF