Review main Ready for review Quiet

96341[BUGFIX] Validation of TCA column type "color"

Daniel Windloff CR 0 V 0 Hard +987 −3 updated 11/06/26, 17:54

Commit message

The`DataHandler->checkValueForColor` transforms
and validates the color values before saving.
Invalid values are not saved anymore.

The following transformation and validation
steps are performed:
- Trimming the input
- Converting named CSS colors to hex
- Ensuring the value is prefixed with `#`
- Converting short hex color notation to long hex
- Limiting the string length
- Adding the default opacity if necessary
- Validating the resulting color value

Test this change

Run a command in your clone of the TYPO3 Core. Then try what the change does and vote on Verified in Gerrit. How to review a patch

Check out patch set 4
git fetch https://review.typo3.org/Packages/TYPO3.CMS refs/changes/41/96341/4 && git checkout FETCH_HEAD
Cherry-pick onto main
git fetch https://review.typo3.org/Packages/TYPO3.CMS refs/changes/41/96341/4 && git cherry-pick FETCH_HEAD

Review

  • Code review CR 0 Needs a vote
  • Verified V 0 Needs a vote
    • core-ci +1 CI

Merge conflicts 24

Issues 1

Files 7

Review log 1115

  1. Daniel Windloff uploaded patch set 1 10/03/26, 05:26

  2. core-ci voted on patch set 1 V -1 10/03/26, 05:34 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/110021

  3. Daniel Windloff uploaded patch set 2 V -1 10/03/26, 05:44

  4. core-ci voted on patch set 2 V +1 10/03/26, 05:52 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/110023

  5. Georg Ringer commented on patch set 2 10/03/26, 18:43

    why transforming short => long + name => hex? don't see a reason for that
  6. Daniel Windloff commented on patch set 2 10/04/26, 06:30

    Reply

    Converting CSS color names to hex values ​​makes sense because the database field has a limited length. Using the long hex format allows the length of the resulting string to be precisely determined. Converting from the short to the long hex format serves only to ensure consistency. This could also be achieved through two additional validation steps and a different default value for the default opacity. While I prefer a consistent format for the entries, I see no technical necessity for it.

    Reply

    For transforming css names to hex is useful, as the default length of the datbase row is limited. Using the long hex format wie exacly know the resulting string length. The transformation from short to long hex is just for consistency. It can be replaced by two more validations and a diffrent default opacity as well. I usually prefer the same kind of entry, but it's no tecnical need I see.
  7. Benni Mack wrote 10/16/26, 07:44

    Topic set to DataHandler
  8. Benjamin Franzke commented on patch set 2 10/23/26, 14:26

    DataHandler.php:1599

    Why should we map named CSS colors, that's a new feature, right? Why do you think that we need such a feature?
  9. Daniel Windloff commented on patch set 2 10/23/26, 15:01

    DataHandler.php:1599 Reply

    I took a look at the color picker in FormEngine. When I specified "black" or "yellow," for example, the corresponding color was displayed and saved correctly. However, the persistence layer assumed the HEX format, but did not enforced it. In practice, only a limited set of color values depending on the string length ​​could be saved. Adding a validation using the HEX format without any replacement of color names would reject those color values ​​that were previously considered valid regarding the feedback from the color picker. That is why I thought this replacement is needed.
  10. Daniel Windloff uploaded patch set 3 V +1 10/24/26, 05:01

  11. core-ci voted on patch set 3 V +1 10/24/26, 05:15 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/112389

  12. Daniel Windloff uploaded patch set 4 V +1 10/26/26, 03:49

  13. core-ci voted on patch set 4 V +1 10/26/26, 03:56 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/112551

  14. Benjamin Franzke commented on patch set 4 11/06/26, 14:25

    DataHandler.php:1599 Reply

    Thanks Daniel, fair point that the picker accepts "red" today. I'd rather not keep a color table in PHP though: the browser knows all CSS colors, so the picker could convert them on change and DataHandler would only accept hex. I've sketched that locally (it also fixes clearing the field, which PS4 broke, and rejects overlong input instead of truncating it). Bigger question, though: do we want to limit this to hex at all? Hex is sRGB only, so oklch()/display-p3 colors can't be stored. That limit already comes from the varchar(7/9) column, so lifting it would be a separate change. Should I push the sketch as a new patch set, or do you want to take it from here?
  15. Daniel Windloff commented on patch set 4 11/06/26, 17:54

    DataHandler.php:1599 Reply Unresolved

    Thanks for your reply. I can not say whether the restriction to HEX should remain or not. My goal here was simply to add server-side validation, which I felt was missing in DataHandler. You are welcome to submit a new patch set featuring the alternative approach.