69180[BUGFIX] Do not break list module due to TypeError
Commit message
Review
-
Code review CR +2 Done
- Oli Bartsch +2
- Christian Kuhn +1
-
Verified V +2 Done
- Oli Bartsch +2
- Christian Kuhn +1
- core-ci +1 CI
Issues 2
Files 1
Review log 1317
-
Daniel Siepmann uploaded patch set 1 05/18/21, 21:11
-
Daniel Siepmann uploaded patch set 2 05/18/21, 21:12
-
core-ci voted on patch set 1 V +1 05/18/21, 21:19 Core CI is happy: https://gitlab.typo3.org/TYPO3/CI/cms/-/pipelines/11644
-
core-ci voted on patch set 2 V +1 05/18/21, 21:22 Core CI is happy: https://gitlab.typo3.org/TYPO3/CI/cms/-/pipelines/11645
-
crell commented on patch set 2 05/18/21, 21:46
I think the issue is that `??` binds lower than `&&`. That means the change I made previously is buggy, and it's getting evaluated as: `$languageField ?? (null && $transOrigPointerField) ?? null` When it should actually be: `($languageField ?? null) && ($transOrigPointerField ?? null)` I realized that later on, but apparently didn't catch all of the ones I'd already done incorrectly. :-/ The fix in this issue should resolve it. Alternatively, keeping the `?? null` (or using `?? false`) and putting in the extra parentheses to group the operators correctly would be more consistent with what most of the rest of those use cases are doing now. -
Oli Bartsch commented on patch set 2 CR -1 05/18/21, 22:46
BackendUtility.php:3193I think this was not the intention of this check. While `?? null` implicit checks the value for not equals FALSE, isset() just checks if the key is set. This would lead to expression being built for empty field names. See previous code: https://review.typo3.org/c/Packages/TYPO3.CMS/+/69012/24/typo3/sysext/backend/Classes/Utility/BackendUtility.php#3193 Therefore, please just wrap those into parentheses. ($GLOBALS['TCA'][$table]['ctrl']['languageField'] ?? null) && ($GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'] ?? null) -
Daniel Siepmann uploaded patch set 3 05/19/21, 05:39
-
Daniel Siepmann commented on patch set 3 05/19/21, 05:41
Reply
Thx, it feels way to complicated for me. That's why I asked you and I've adjusted the patch to your suggestion.BackendUtility.php:3193ReplyDone It feels way to complicated for me. I guess TYPO3 checks if those fields are configured. I would understand an additional `is_string()` as well as `!empty()`, etc. But those brace explosion and `null` feels strange. How does this check if fields are not empty? It still can be anything except null (which isset would check), right? I just don't get it, that's why I asked Larry to check my proposed change. -
core-ci voted on patch set 3 V +1 05/19/21, 05:49 Core CI is happy: https://gitlab.typo3.org/TYPO3/CI/cms/-/pipelines/11658
-
Alexander Schnitzler commented on patch set 3 05/19/21, 07:17
BackendUtility.php:3193Reply> isset() just checks if the key is set I don't think that's true. isset checks if the key exists and if the value is not null. > $a = ['b' => null]; > isset($a['b']); // false Null coalescence here does the same thing as isset because the output of the expression is not used outside the condition. That's why I don't see any reason to use it in favor of isset unless the values are stored in an intermediate variable for further checks. My suggestion here would be to use null coalescence but store the values in separate variables and perform an early return. > $languageField = (string)($GLOBALS['TCA'][$table]['ctrl']['languageField'] ?? ''); > $transOrigPointerField = (string)($GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'] ?? ''); > > if ($languageField === '' || $transOrigPointerField === '') { > return $msg ? '' : '0'; > } > > // at this point you only deal with non-empty strings. This makes it perfectly clear to the reader that in order to perform the following query, both fields need to contain data. And if someone stores a non castable value in one of those fields, it's only right to get a TypeError from the explicit casting to string IMHO. The docs are clear on this. If defined, those fields contain non empty strings. -
Oli Bartsch commented on patch set 3 V +1 CR +1 05/19/21, 08:09
BackendUtility.php:3193Reply> I don't think that's true. isset checks if the key exists and if the value is not null. Yes, isset checks also if not null but does not check if the value is equals TURE. https://3v4l.org/9TAdL. So using isset and null coalescing is not the same. -
Christian Kuhn updated the commit message in patch set 4 05/19/21, 08:52
-
Christian Kuhn voted on patch set 4 V +1 CR +1 05/19/21, 08:54
-
Oli Bartsch voted on patch set 4 V +2 CR +2 05/19/21, 08:56
-
core-ci voted on patch set 4 V +1 05/19/21, 09:01 Core CI is happy: https://gitlab.typo3.org/TYPO3/CI/cms/-/pipelines/11666
-
Oli Bartsch merged patch set 5 05/19/21, 09:02
-
Alexander Schnitzler commented on patch set 5 05/19/21, 10:10
BackendUtility.php:3193ReplyTrue, it's not the same and given the current code, where checking for existence AND type with an implicit casting to bool, this is technically correct but impossible for humans to read (quickly). I think that my approach is bit more verbose and user friendly and guarantees more type safety than this approach. With the current approach all values that evaluate to bool true will end up in the query builder whereas with my suggested approach, the contract is quite clear and a possible TypeError occurs at a place where users understand the root cause.