Review main Merged

87457[FEATURE] Allow boolean and arbitrary values in HTML attributes

Ayke Halder CR +2 V +2 Hard +270 −73 updated 10/02/26, 16:35

Commit message

GeneralUtility::implodeAttributes() gets a new option
$convertValues to render HTML5 attributes properly:

* true renders an attribute without a value, e.g. "defer"
  instead of defer="defer"
* false and null omit the attribute
* Stringable objects are cast to string
* other arrays and objects are JSON-encoded and escaped

The option is used in all places that build script, link
and style tags, which now allow to pass boolean values:

* PageRenderer (link, script, inline style and inline
  script)
* AssetRenderer
* JavaScriptRenderer

In addition, tags that were assembled by hand are now
built with implodeAttributes():

* GenericMetaTagManager and AbstractMetaTagManager
  (<meta> tags)
* VideoTagRenderer and AudioTagRenderer, where boolean
  attributes such as "controls" or "loop" can now be
  passed as true
* RequestHandler (<html> tag from config.htmlTag)

Review

  • Code review CR +2 Done
    • Georg Ringer +2
    • Benni Mack +1
  • Verified V +2 Done
    • Georg Ringer +2
    • Benni Mack +1
    • core-ci +1 CI

Issues 1

Files 13

Review log 1723

  1. Ayke Halder uploaded patch set 1 12/11/24, 17:39

  2. Ayke Halder commented on patch set 1 12/11/24, 17:40

    Rebase of closed 76103: [WIP][TASK] Allow arbitrary values in attributes | https://review.typo3.org/c/Packages/TYPO3.CMS/+/76103/4
  3. core-ci voted on patch set 1 V -1 12/11/24, 17:49 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/70968

  4. Ayke Halder uploaded patch set 2 V -1 12/11/24, 18:31

  5. core-ci voted on patch set 2 V -1 12/11/24, 18:37 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/70972

  6. Ayke Halder uploaded patch set 3 V -1 12/11/24, 18:50

  7. core-ci voted on patch set 3 V +1 12/11/24, 18:55 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/70977

  8. Ayke Halder commented on patch set 3 12/11/24, 19:08

    Patchset 1 -> 3 just implements fixes to make Core CI happy: https://review.typo3.org/c/Packages/TYPO3.CMS/+/87457/1..3 Especially it should be evaluated if activating attribute-name conversion to lower-case letters is the intended behaviour: E.g. `$attr['CustomAttribute' => 'test']` becomes `<tag customattribute="test">`
  9. Ayke Halder uploaded patch set 4 V +1 12/11/24, 19:17

  10. core-ci voted on patch set 4 V +1 12/11/24, 19:24 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/70980

  11. Ayke Halder commented on patch set 4 12/11/24, 19:44

    Patchset 4 implements changes to the attribute mapping: https://review.typo3.org/c/Packages/TYPO3.CMS/+/87457/3..4 See `GeneralUtilityTest::implodeAttributesArbitraryDataProvider`: ---- ```php $attr = [ 'href' => 'https://example.com';, 'title' => 'test', 'aria-hidden' => 'true', 'defer' => true, 'disabled' => true, 'nomodule' => true ]; ``` Result: `href="https://example.com"; title="test" aria-hidden="true" defer disabled nomodule` ---- ```php $attr = [ 'href' => 'https://example.com';, 'title' => '', 'aria-hidden' => 'false', 'defer' => false, 'disabled' => true, 'nomodule' => null ]; unset($attr['disabled']); ``` Result: `href="https://example.com"; aria-hidden="false"`
  12. Benni Mack uploaded patch set 5 V +1 09/23/26, 20:51

  13. Benni Mack marked it ready for review 09/23/26, 20:52

  14. core-ci voted on patch set 5 V +1 09/23/26, 21:06 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/109114

  15. Benni Mack updated the commit message in patch set 6 V +1 09/28/26, 12:44

  16. Benni Mack voted on patch set 6 CR +1 V +1 09/28/26, 12:44

  17. core-ci voted on patch set 6 V +1 09/28/26, 12:54 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/109421

  18. Georg Ringer voted on patch set 6 CR +2 V +2 09/30/26, 07:31

  19. Georg Ringer merged patch set 7 09/30/26, 07:31

  20. Torben Hansen commented on patch set 7 09/30/26, 08:47

    Sorry for being late at the party. I think we should continue to escape the keys of possible `data-` attributes in the VideoTagRenderer and AudioTagRenderer. AFAICs this is not handled somewhere else now.

    VideoTagRenderer.php:73 Unresolved

    Why has the escaping of the key been removed?
  21. Ayke Halder commented on patch set 7 09/30/26, 09:55

    Reply Unresolved

    Good point! This change is from December 2024… and then got rebased in 2026. ---- On one hand we might want to escape all keys directly inside ̀GeneralUtility::implodeAttributes()`. On the other hand: Just don't escape the HTML attributes as nearly every character is allowed! Just clean those non-viable control-characters: `='">` and ` ` (all kind of blanks) See https://stackoverflow.com/questions/925994/what-characters-are-allowed-in-an-html-attribute-name/53563849#53563849

    AbstractMetaTagManager.php:233 Unresolved

    E.g. here the keys are escaped before calling `GeneralUtility::implodeAttributes()`

    GeneralUtility.php:1001 Unresolved

    Escape the keys here…

    GeneralUtility.php:1019

    … and also escape the keys here.
  22. Ayke Halder commented on patch set 7 09/30/26, 09:58

    GeneralUtility.php:1019 Reply

    Not here.

    GeneralUtility.php:1021 Unresolved

    … and also escape the keys here.
  23. Benni Mack commented on patch set 7 10/02/26, 16:35

    Thanks for the feedback @mail@ayke-halder.de and @derhansen@gmail.com - I did a followup here: https://review.typo3.org/c/Packages/TYPO3.CMS/+/96323