Review main Merged

86664[BUGFIX] Cast tag-content of several ViewHelpers to string

Georg Ringer CR +2 V +2 Hard +414 −19 updated 11/19/24, 19:57

Commit message

Several Fluid ViewHelpers used the method:

```
$this->tag->setContent($this->renderChildren());
```

However, in many cases specifying an integer as a tag content (for
example in pagination cases) is valid:

```
<f:for each="{1:'step1', 2:'step2'}"
       as='i'
       iteration='iterator'
       key="k">
    <f:link.action action="{i}">{k}</f:link.action>
</f:for>
```

This would lead to an exception, because the `setContent()` method
expects a a string.

Several ViewHelpers have now been adapted to cast the result of
`renderChildren` to a string.

Tests verifying this behaviour are added. Some cases where ViewHelpers
already had string-casting in effect are now secured with a test, too.

Notable exemptions of ViewHelpers where no string casting has been
applied:

- EXT:form VHs already seem to take care of proper renderChildren()
  handling.
- f:uri.action and f:uri.page do not accept tag based content.
- ce:link.clickEnlarge, sg:example, sg:code, sg:colorscheme do
  not make sense to receive non-string input, exceptions still

Note that for <dashboard:widget.button> no functional test exists yet,
and is beyond scope of this patch to be added.

Drive-by fix of adding (string) cast to an integer-based
'title' attribute for <f:be.infobox> added as well.

Review

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

Issues 1

Files 40

Show 20 more files

Review log 2329

Show 34 earlier messages
  1. Georg Ringer uploaded patch set 1 10/20/24, 08:27

  2. Georg Ringer commented on patch set 1 10/20/24, 08:27

    This change is ready for review.
  3. core-ci voted on patch set 1 V +1 10/20/24, 08:33 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/68250

  4. Garvin Hicking commented on patch set 1 V +1 10/20/24, 09:58

    Does it not affect 13.4? Maybe we could add a simple test for it that uses tagcontent with int and string once
  1. Georg Ringer updated the commit message in patch set 2 V +1 10/21/24, 06:34

  2. core-ci voted on patch set 2 V +1 10/21/24, 06:39 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/68280

  3. Benni Mack voted on patch set 2 CR +1 V +1 10/21/24, 08:29

  4. Oli Bartsch commented on patch set 2 10/21/24, 08:32

    Should we adjust similar VHs (link.page, link.external) as well?
  5. Christian Kuhn commented on patch set 2 10/21/24, 10:45

    shouldn't be too hard to functional test this, too. and we may want to change the code to actively throw if renderChildren can *not* be cast to string, maybe? that would turn an error into a exception, which is good.
  6. Garvin Hicking commented on patch set 2 CR -1 10/22/24, 07:50

    On it to add tests and apply to other viewhelpers
  7. Garvin Hicking uploaded patch set 3 CR +1 V +1 10/22/24, 10:32

    Add tests add more cases
  8. core-ci voted on patch set 3 V -1 10/22/24, 10:41 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/68361

  9. Garvin Hicking uploaded patch set 4 V -1 10/22/24, 10:57

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

  11. Garvin Hicking commented on patch set 4 CR +1 V +1 10/22/24, 11:36

    Reply

    That was a rabbit-hole, whelp. Note that a few tests needed to be created to verify existing behaviour. Let me know if this all needs to become a pre-patch, or if we can address it in one-go.
    Whelp, this
  12. Garvin Hicking commented on patch set 4 10/22/24, 11:40

    Reply

    Done

    Reply

    Blowing that up for then needed assertions of all the tests would be quite some work. Maybe do that in a follow-up?
  13. Simon Praetorius commented on patch set 4 11/19/24, 13:23

    InfoboxViewHelper.php:89

    How is this related to the original problem?

    TemplateIntegerTagContent.html:6

    Isn't this a syntax error because the tag is not properly closed? Seems like the test doesn't run properly.
  14. Garvin Hicking uploaded patch set 5 CR +1 V +1 11/19/24, 14:12

  15. Garvin Hicking commented on patch set 5 CR +1 V +1 11/19/24, 14:13

    InfoboxViewHelper.php:89 Reply

    This was a drive-by fix actually, because when in the tests the 'title' argument is missing it will yield an error in the functional tests. Would it be ok for you to include this here? ``` 1) TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Be\InfoboxViewHelperTest::integerAsButtonRenderChildrenRendersTagContent TypeError: htmlspecialchars(): Argument #1 ($string) must be of type string, int given /Users/garvin/TYPO3/typo3-core-bugreproduce-base/typo3-core/typo3/sysext/fluid/Classes/ViewHelpers/Be/InfoboxViewHelper.php:110 /Users/garvin/TYPO3/typo3-core-bugreproduce-base/typo3-core/vendor/typo3fluid/fluid/src/Core/ViewHelper/AbstractViewHelper.php:261 /Users/garvin/TYPO3/typo3-core-bugreproduce-base/typo3-core/vendor/typo3fluid/fluid/src/Core/ViewHelper/ViewHelperInvoker.php:69 /Users/garvin/TYPO3/typo3-core-bugreproduce-base/typo3-core/vendor/typo3fluid/fluid/src/Core/Parser/SyntaxTree/ViewHelperNode.php:125 /Users/garvin/TYPO3/typo3-core-bugreproduce-base/typo3-core/vendor/typo3fluid/fluid/src/Core/Parser/SyntaxTree/AbstractNode.php:59 /Users/garvin/TYPO3/typo3-core-bugreproduce-base/typo3-core/vendor/typo3fluid/fluid/src/Core/Parser/SyntaxTree/AbstractNode.php:41 /Users/garvin/TYPO3/typo3-core-bugreproduce-base/typo3-core/vendor/typo3fluid/fluid/src/Core/ViewHelper/AbstractViewHelper.php:305 /Users/garvin/TYPO3/typo3-core-bugreproduce-base/typo3-core/vendor/typo3fluid/fluid/src/Core/ViewHelper/AbstractViewHelper.php:282 /Users/garvin/TYPO3/typo3-core-bugreproduce-base/typo3-core/vendor/typo3fluid/fluid/src/ViewHelpers/ForViewHelper.php:134 /Users/garvin/TYPO3/typo3-core-bugreproduce-base/typo3-core/vendor/typo3fluid/fluid/src/Core/ViewHelper/AbstractViewHelper.php:261 /Users/garvin/TYPO3/typo3-core-bugreproduce-base/typo3-core/vendor/typo3fluid/fluid/src/Core/ViewHelper/ViewHelperInvoker.php:69 /Users/garvin/TYPO3/typo3-core-bugreproduce-base/typo3-core/vendor/typo3fluid/fluid/src/Core/Parser/SyntaxTree/ViewHelperNode.php:125 /Users/garvin/TYPO3/typo3-core-bugreproduce-base/typo3-core/vendor/typo3fluid/fluid/src/Core/Parser/SyntaxTree/AbstractNode.php:59 /Users/garvin/TYPO3/typo3-core-bugreproduce-base/typo3-core/vendor/typo3fluid/fluid/src/Core/Parser/SyntaxTree/AbstractNode.php:41 /Users/garvin/TYPO3/typo3-core-bugreproduce-base/typo3-core/vendor/typo3fluid/fluid/src/Core/Parser/SyntaxTree/RootNode.php:30 /Users/garvin/TYPO3/typo3-core-bugreproduce-base/typo3-core/vendor/typo3fluid/fluid/src/Core/Parser/ParsingState.php:88 /Users/garvin/TYPO3/typo3-core-bugreproduce-base/typo3-core/vendor/typo3fluid/fluid/src/View/AbstractTemplateView.php:146 /Users/garvin/TYPO3/typo3-core-bugreproduce-base/typo3-core/typo3/sysext/fluid/Tests/Functional/ViewHelpers/Be/InfoboxViewHelperTest.php:42 ```

    TemplateIntegerTagContent.html:6 Reply

    Good catch; I created a file before I inlined the test content without needing to utilize a file. Removed it now.
  16. core-ci voted on patch set 5 V +1 11/19/24, 14:19 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/69714

  17. Simon Praetorius commented on patch set 5 11/19/24, 15:52

    InfoboxViewHelper.php:89 Reply

    Acknowledged
  18. Simon Praetorius commented on patch set 5 CR +1 V +1 11/19/24, 15:54

    Reply

    We talked about this and decided that (for now) we are fine with the simple string cast. This is probably a ToDo for the Fluid API.
  19. Garvin Hicking updated the commit message in patch set 6 CR +1 V +1 11/19/24, 17:50

  20. Simon Praetorius voted on patch set 6 CR +1 V +1 11/19/24, 17:53

  21. core-ci voted on patch set 6 V +1 11/19/24, 17:58 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/69734

  22. Garvin Hicking voted on patch set 6 CR +1 V +1 11/19/24, 18:12

  23. Christian Kuhn voted on patch set 6 CR +1 11/19/24, 19:55

  24. Garvin Hicking voted on patch set 6 CR +2 V +2 11/19/24, 19:57

  25. Garvin Hicking merged patch set 7 11/19/24, 19:57