Project

General

Profile

Actions

Bug #99503

closed

Inline script concatenation requires scripts to have trailing ";"

Added by Jonas Eberle over 1 year ago. Updated 6 months ago.

Status:
Resolved
Priority:
Must have
Assignee:
-
Category:
Frontend
Target version:
-
Start date:
2023-01-10
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
12
PHP Version:
Tags:
javascript
Complexity:
easy
Is Regression:
Sprint Focus:

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)


Related issues 1 (0 open1 closed)

Related to TYPO3 Core - Bug #102328: Regression in cObjGetResolved2023-11-06

Actions
Actions #1

Updated by Jonas Eberle over 1 year ago

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)
}

Actions #2

Updated by Jonas Eberle over 1 year ago

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.

Actions #3

Updated by Gerrit Code Review over 1 year ago

  • Status changed from New to Under Review

Patch set 1 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/77320

Actions #4

Updated by Jonas Eberle over 1 year ago

  • Subject changed from config.concatenateJs requires scripts to finish with ";" to Inline script concatenation requires scripts to have trailing ";"
Actions #5

Updated by Gerrit Code Review about 1 year ago

Patch set 2 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/77320

Actions #6

Updated by Gerrit Code Review 9 months ago

Patch set 3 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/77320

Actions #7

Updated by Gerrit Code Review 9 months ago

Patch set 4 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/77320

Actions #8

Updated by Gerrit Code Review 9 months ago

Patch set 5 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/77320

Actions #9

Updated by Gerrit Code Review 6 months ago

Patch set 1 for branch 11.5 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/81686

Actions #10

Updated by Gerrit Code Review 6 months ago

Patch set 1 for branch 12.4 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/81687

Actions #11

Updated by Gerrit Code Review 6 months ago

Patch set 2 for branch 11.5 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/81686

Actions #12

Updated by Anonymous 6 months ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
Actions #13

Updated by Rafael Kähm 6 months ago

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 [];
        }

Actions #14

Updated by Jonas Eberle 6 months ago

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"?

Actions #15

Updated by Benjamin Franzke 6 months ago

Actions #16

Updated by Benjamin Franzke 6 months ago

Thanks for the report Rafael.
Please find a fix in:

81698: [BUGFIX] Fix possible regression in cObjGet() | https://review.typo3.org/c/Packages/TYPO3.CMS/+/81698

Actions

Also available in: Atom PDF