[BUGFIX] Allow "distinct" in select.selectFields 72/38372/4
authorSusanne Moog <look@susi.dev>
Thu, 5 Mar 2020 08:18:06 +0000 (09:18 +0100)
committerFrank Nägler <frank.naegler@typo3.org>
Fri, 6 Mar 2020 12:36:11 +0000 (13:36 +0100)
Add "distinct" into the whitelist of allowed select parts.

Resolves: #43114
Releases: master, 9.5
Change-Id: I8ae6561ff6067117b9d5acb6c976966fecaee96a
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/38372
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Benni Mack <benni@typo3.org>
Tested-by: Frank Nägler <frank.naegler@typo3.org>
Reviewed-by: Benni Mack <benni@typo3.org>
Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Frank Nägler <frank.naegler@typo3.org>
typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php
typo3/sysext/frontend/Tests/Functional/ContentObject/ContentObjectRendererTest.php

index db9eaa8..35a5ee9 100644 (file)
@@ -6707,7 +6707,7 @@ class ContentObjectRenderer implements LoggerAwareInterface
         $matchEnd = '(\\s*,|\\s*$)/';
         $necessaryFields = ['uid', 'pid'];
         $wsFields = ['t3ver_state'];
-        if (isset($GLOBALS['TCA'][$table]) && !preg_match($matchStart . '\\*' . $matchEnd, $selectPart) && !preg_match('/(count|max|min|avg|sum)\\([^\\)]+\\)/i', $selectPart)) {
+        if (isset($GLOBALS['TCA'][$table]) && !preg_match($matchStart . '\\*' . $matchEnd, $selectPart) && !preg_match('/(count|max|min|avg|sum)\\([^\\)]+\\)|distinct/i', $selectPart)) {
             foreach ($necessaryFields as $field) {
                 $match = $matchStart . $field . $matchEnd;
                 if (!preg_match($match, $selectPart)) {
index c860e4e..57cfe1d 100644 (file)
@@ -180,6 +180,15 @@ class ContentObjectRendererTest extends FunctionalTestCase
                 [
                     'SELECT' => 'avg(crdate)'
                 ]
+            ],
+            'single distinct, add nothing' => [
+                'tt_content',
+                [
+                    'selectFields' => 'DISTINCT crdate'
+                ],
+                [
+                    'SELECT' => 'DISTINCT crdate'
+                ]
             ]
         ];