Review 13.4 Merged

90114[TASK] Add tests and adjust ambiguity in AstConstantCommentVisitor

Garvin Hicking CR +2 V +2 Expert +1090 −1 updated 07/23/25, 12:20

Commit message

The `AstConstantCommentVisitor` is used to parse
`ext_conf_template.txt` files of extensions. The file provides
TypoScript comments which are parsed as constants to allow
GUI configuration mapping in the TypoScript Constant Editor.

A comment string like this:

```
  # cat=Integer/101/15; type=int[-5--1]; label=Int 6 - range (neg start, neg end)
```

is parsed as syntax (yes, yuck) and specifically the argument
`type=int[-5--1]` is tokenized and parsed into a min/max range.

This was performed with ambiguous interpretation with `$start/$stop`
temporary variables and character-by-character parsing to find out
if a number is positive or negative.

The old comparison:

```
} elseif ($stop === '' && $char === '-') {
```

was never possible to trigger though, because $stop was initialized
as 'null'. This only worked before strict type declarations where
enabled in legacy code, likely.

Funnily, this oddity had no real-life implications as the newly
added tests reveal.

Before this patch, `$negativeStop` could never be set to `true`,
thus the later code:

```
if ($negativeStop) {
    $stop = (int)$stop * -1;
}
```

was never triggered. So a value like `1` (from `-5--1`) would not be
transformed into `-1` theoretically. Luckily though, in this case
`$stop` was already set to `-1` (note that it would be a TWO character
string then).

When fixing this code to use a proper `$stop === null` comparison,
the end result is still the same, and `$stop` will be set to `-1`.

Tests verify that the behaviour is the same before and after the
patch. With this patch, PHPStan will no longer report the condition
to be unused, unlocking an update to PHPStan 2.1.19 without a change
in the baseline.

Review

  • Code review CR +2 Done
    • Garvin Hicking +2
  • Verified V +2 Done
    • Garvin Hicking +2
    • core-ci +1 CI

Issues 3

Files 3

Review log 58

  1. Garvin Hicking commented on patch set 1 07/22/25, 09:09

    Cherry Picked from branch main.
  2. Garvin Hicking updated the commit message in patch set 2 07/22/25, 09:10

  3. core-ci voted on patch set 1 V -1 07/22/25, 09:20 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/82107

  4. core-ci voted on patch set 2 V -1 07/22/25, 09:25 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/82109

  5. Garvin Hicking commented on patch set 3 V -1 07/22/25, 17:36

    Cherry Picked from branch main.
  6. core-ci voted on patch set 3 V +1 07/22/25, 17:42 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/82135

  7. Garvin Hicking voted on patch set 3 CR +2 V +2 07/23/25, 12:20

  8. Garvin Hicking merged patch set 4 07/23/25, 12:20