[BUGFIX] Respect lowercase „as“ in quoteIdentifiersForSelect 76/53576/2
authorFrank Naegler <frank.naegler@typo3.org>
Mon, 24 Jul 2017 09:33:55 +0000 (11:33 +0200)
committerJan Helke <typo3@helke.de>
Mon, 24 Jul 2017 11:12:25 +0000 (13:12 +0200)
QueryBuilder->quoteIdentifiersForSelect() now supports lowercase
and mixedcase „as“ to detect alias names for fields.

Resolves: #81946
Releases: master, 8.7
Change-Id: Ib79088e3dd677efd24674d7aa9f5c3f4c973ec8d
Reviewed-on: https://review.typo3.org/53576
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Jan Helke <typo3@helke.de>
Tested-by: Jan Helke <typo3@helke.de>
typo3/sysext/core/Classes/Database/Query/QueryBuilder.php
typo3/sysext/core/Tests/Unit/Database/Query/QueryBuilderTest.php

index 1a900c3..0d01304 100644 (file)
@@ -969,7 +969,7 @@ class QueryBuilder
     public function quoteIdentifiersForSelect(array $input): array
     {
         foreach ($input as &$select) {
-            list($fieldName, $alias, $suffix) = GeneralUtility::trimExplode(' AS ', $select, 3);
+            list($fieldName, $alias, $suffix) = GeneralUtility::trimExplode(' AS ', str_ireplace(' as ', ' AS ', $select), 3);
             if (!empty($suffix)) {
                 throw new \InvalidArgumentException(
                     'QueryBuilder::quoteIdentifiersForSelect() could not parse the input "' . $input . '"',
index 14b016c..b2715d3 100644 (file)
@@ -282,6 +282,9 @@ class QueryBuilderTest extends UnitTestCase
         $this->subject->select('aField', 'anotherField');
     }
 
+    /**
+     * @return array
+     */
     public function quoteIdentifiersForSelectDataProvider()
     {
         return [
@@ -313,6 +316,30 @@ class QueryBuilderTest extends UnitTestCase
                 'tableName.fieldName AS anotherTable.anotherFieldName',
                 '"tableName"."fieldName" AS "anotherTable"."anotherFieldName"',
             ],
+            'fieldName as anotherFieldName' => [
+                'fieldName as anotherFieldName',
+                '"fieldName" AS "anotherFieldName"',
+            ],
+            'tableName.fieldName as anotherFieldName' => [
+                'tableName.fieldName as anotherFieldName',
+                '"tableName"."fieldName" AS "anotherFieldName"',
+            ],
+            'tableName.fieldName as anotherTable.anotherFieldName' => [
+                'tableName.fieldName as anotherTable.anotherFieldName',
+                '"tableName"."fieldName" AS "anotherTable"."anotherFieldName"',
+            ],
+            'fieldName aS anotherFieldName' => [
+                'fieldName aS anotherFieldName',
+                '"fieldName" AS "anotherFieldName"',
+            ],
+            'tableName.fieldName aS anotherFieldName' => [
+                'tableName.fieldName aS anotherFieldName',
+                '"tableName"."fieldName" AS "anotherFieldName"',
+            ],
+            'tableName.fieldName aS anotherTable.anotherFieldName' => [
+                'tableName.fieldName aS anotherTable.anotherFieldName',
+                '"tableName"."fieldName" AS "anotherTable"."anotherFieldName"',
+            ],
         ];
     }