Review main Merged

90112[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
    • Christian Kuhn +1
    • Oliver Hader +1
    • Simon Schaufelberger +1
  • Verified V +2 Done
    • Garvin Hicking +2
    • Christian Kuhn +1
    • Oliver Hader +1
    • Simon Schaufelberger +1
    • core-ci +1 CI

Issues 3

Files 3

Review log 1621

  1. Garvin Hicking uploaded patch set 1 07/22/25, 09:03

  2. Garvin Hicking updated the commit message in patch set 2 07/22/25, 09:09

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

  4. Garvin Hicking uploaded patch set 3 07/22/25, 09:17

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

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

  7. Garvin Hicking uploaded patch set 4 V -1 07/22/25, 09:33

    Once more with feeling
  8. Oliver Hader commented on patch set 3 07/22/25, 09:37

    I think this is actually a bugfix, since `int[-5--1]` was evaluated to the range of `[-5;+1]` before - now it's the correct range `[-5;-1]`. The test cases (actually, it's just one test with multiple assertions hidden as test sets) might be split up to have the parser only work on that particular TypoScript snippet - or in case the generic `ext_conf_template.txt` shall stay, put as multiple assertions into one test method.
  9. Oliver Hader commented on patch set 4 V +1 07/22/25, 09:38

    Reply

    By just looking at the functionality and behavior, this change looks good.
  10. core-ci voted on patch set 4 V +1 07/22/25, 09:42 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/82114

  11. Garvin Hicking commented on patch set 4 07/22/25, 09:50

    Reply

    The `[-1--1]` case was actually also properly resolved before this bugfix; `$stop` then gets evaluated to `-1` (not `1`) to make it fall into place (see commit message). So IMO not a true bugfix, but it's quirky. About rewriting the test, I'll likely not have time to do that today. I wanted to avoid too much work into splitting all the chunks up and thought it's better to have this than no test (or just a very small test for this specific case). Doing multiple assertions in one test was something that I tried to avoid due to code review comments in other patches that said to not do that. I'm fine if anyone could/would rework the tests though!
  12. Simon Schaufelberger voted on patch set 4 CR +1 V +1 07/22/25, 12:18

  13. Garvin Hicking uploaded patch set 5 CR +1 V +1 07/22/25, 12:28

  14. Garvin Hicking commented on patch set 5 07/22/25, 12:30

    Reply

    I've reworked the test so that we now have no static member property to 'cache' the expectations, but a single test method that iterates on them. That's all I can offer. Manually juggling these 44 assertions was quite some work; the test method also contains a note why it is what it is. Hope that works for everyone.
  15. core-ci voted on patch set 5 V +1 07/22/25, 12:36 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/82125

  16. Christian Kuhn voted on patch set 5 CR +1 V +1 07/22/25, 14:14

  17. Simon Schaufelberger voted on patch set 5 CR +1 V +1 07/23/25, 09:03

  18. Oliver Hader voted on patch set 5 CR +1 V +1 07/23/25, 12:09

  19. Oliver Hader commented on patch set 5 07/23/25, 12:09

    Reply

    Thx 😊
  20. Garvin Hicking voted on patch set 5 CR +2 V +2 07/23/25, 12:19

  21. Garvin Hicking merged patch set 6 07/23/25, 12:20