Review main Merged

61122[BUGFIX] Prevent PHP Warning with TCA selectTree

Markus Klein CR +2 V +2 Easy +7 −4 updated 08/02/19, 13:27

Commit message

Make sure there is actually an 'items' array in the processedTCA
before validating the items.

Review

  • Code review CR +2 Done
    • Anja Leichsenring +2
    • Oliver Klee +1
    • Tymoteusz Motylewski +1
  • Verified V +2 Done
    • Anja Leichsenring +2
    • Tymoteusz Motylewski +1
    • TYPO3com +1 CI

Issues 1

Files 1

Review log 2427

Show 12 earlier messages
  1. Markus Klein uploaded patch set 1 06/24/19, 16:45

  2. TYPO3com voted on patch set 1 V +1 06/24/19, 16:57 Completed build in 11m 21s on Mon, 24 Jun, 06:57 PM Test Summary: 46478 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-34521

  1. Joerg Kummer voted on patch set 1 CR +1 06/24/19, 17:01

  2. Joerg Kummer commented on patch set 1 06/24/19, 17:23

    I can't verify, cause i can't reproduce to get PHP warning (in v8.7 and master)
  3. Oliver Klee voted on patch set 1 CR +1 06/24/19, 18:42

  4. Markus Klein commented on patch set 1 06/24/19, 19:10

    @Jörg: I added a bit more information to forge which might be relevant to reproduce
  5. Alexander Schnitzler commented on patch set 1 CR -1 06/25/19, 13:31

    TcaRecordTitle.php:237

    Please let's not introduce new empty checks and use a proper check here. What do you desire to check? The type, the length or both? What about this instead? if (count($fieldConfig['items'] ?? []) > 0)
  6. Alexander Schnitzler commented on patch set 1 06/25/19, 13:38

    TcaRecordTitle.php:237 Reply

    Sorry, this doesn't check if the entry is an array. if (isset($fieldConfig['items']) && is_array($fieldConfig['items']) && count($fieldConfig['items']) > 0) This does only the necessary checks, returns early and is also more verbose than the empty check.
  7. Oliver Klee commented on patch set 1 06/25/19, 13:53

    TcaRecordTitle.php:237 Reply

    The count is not needed in that case as a foreach on an empty array is a no-op.
  8. Alexander Schnitzler commented on patch set 1 06/25/19, 14:01

    TcaRecordTitle.php:237 Reply

    Well, you are right that the count check isn't necessary but not for the reason that there is a loop. $fieldConfig['items'] isn't used in a loop here but in the array_column call. We need to make sure that $fieldConfig['items'] is an array and empty would return true for non-empty strings here as well. And you can never trust user data.
  9. Oliver Klee commented on patch set 1 06/25/19, 14:03

    TcaRecordTitle.php:237 Reply

    You are right, and I think you have misunderstood me. :-) I'm fine with the isset and is_array. I only think that the count is not necessary.
  10. Alexander Schnitzler commented on patch set 1 06/25/19, 14:05

    TcaRecordTitle.php:237 Reply

    No no, I got you :) We remove the count and we're fine.
  11. Markus Klein commented on patch set 1 06/26/19, 19:17

    TcaRecordTitle.php:237 Reply

    Empty is just right here. We need to check emptiness and existence. It is IMO not necessary to check for array type here. Either we have a bug in Core if this is not an array (which is okay to trigger any sort of hard error then) or someone coded the items array in TCA manually and wrong (hard error okay too). So we can rely on being an array, if set.
  12. Alexander Schnitzler commented on patch set 1 06/27/19, 06:42

    TcaRecordTitle.php:237 Reply

    If $fieldConfig['items'] is an array, `empty()` checks just the right thing, true. But `empty()` itself is an anti pattern due to the fact that its exact functioning is dependent on the type it operates on. We can let `array_column` fail with a possible TypeError here, but we could also properly deal with the user input, detect a wrong configuration and act accordingly, like throwing an Exception that specifically tells the user what's wrong. However, my main issue is with `empty()` as this is a shorthand expression which equals `(!isset($v) || $v != true)` which is a non type-safe check. imo we should avoid empty in general and use type safe checks that are more verbose.
  13. Markus Klein commented on patch set 1 06/27/19, 06:47

    TcaRecordTitle.php:237 Reply Unresolved

    We obviously have a different take on empty(). IMO it's the best choice in most situations, simply because it internally is as fast as isset() due to being compiled to a single opcode - in contrast to the !isset($v) || !$v thingy. IMO we don't need a better error message than what PHP already delivers when items is not an array. It already tells us that it expects an array here.
  14. Markus Klein rebased onto patch set 2 07/21/19, 22:38

  15. TYPO3com voted on patch set 2 V +1 07/21/19, 22:50 Completed build in 11m 54s on Mon, 22 Jul, 12:50 AM Test Summary: 47159 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-35254

  16. Andreas Kienast voted on patch set 2 V +1 CR +1 07/22/19, 06:57

  17. Oliver Klee voted on patch set 2 CR +1 07/22/19, 14:56

  18. Tymoteusz Motylewski commented on patch set 2 07/22/19, 19:41

    TcaRecordTitle.php:239

    shouldn't the array_column($fieldConfig['items']) be taken outside the foreach loop?
  19. Markus Klein commented on patch set 3 07/22/19, 20:13

    Published edit on patch set 2.
  20. Markus Klein commented on patch set 3 07/22/19, 20:14

    TcaRecordTitle.php:239 Reply

    Done
  21. TYPO3com voted on patch set 3 V +1 07/22/19, 20:24 Completed build in 10m 58s on Mon, 22 Jul, 10:24 PM Test Summary: 47160 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-35276

  22. Oliver Klee voted on patch set 3 CR +1 07/22/19, 21:39

  23. Tymoteusz Motylewski voted on patch set 3 V +1 CR +1 07/23/19, 05:56

  24. Anja Leichsenring voted on patch set 3 V +2 CR +2 08/02/19, 13:27

  25. Anja Leichsenring merged patch set 4 08/02/19, 13:27