[BUGFIX] Skip quoted fields in insertData 72/53172/7
authorJigal van Hemert <jigal.van.hemert@typo3.org>
Thu, 8 Jun 2017 21:22:44 +0000 (23:22 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Tue, 20 Jun 2017 10:45:19 +0000 (12:45 +0200)
While parsing the input value for expressions inside curly brackets
it must skip quoted field names which are also in curly brackets
but start with a '#'.

Resolves: #81492
Related: #80506
Releases: master, 8.7
Change-Id: Ic58fcdcbb68108ac77da746db3e6a442515ce7ea
Reviewed-on: https://review.typo3.org/53172
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Anja Leichsenring <anja.leichsenring@typo3.com>
Tested-by: Anja Leichsenring <anja.leichsenring@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php
typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php

index c790daf..b0d7d1f 100644 (file)
@@ -3277,8 +3277,13 @@ class ContentObjectRenderer
     }
 
     /**
-     * Implements the "insertData" property of stdWrap meaning that if strings matching {...} is found in the input string they will be substituted with the return value from getData (datatype) which is passed the content of the curly braces.
-     * Example: If input string is "This is the page title: {page:title}" then the part, '{page:title}', will be substituted with the current pages title field value.
+     * Implements the "insertData" property of stdWrap meaning that if strings matching {...} is found in the input string they
+     * will be substituted with the return value from getData (datatype) which is passed the content of the curly braces.
+     * If the content inside the curly braces starts with a hash sign {#...} it is a field name that must be quoted by Doctrine
+     * DBAL and is skipped here for later processing.
+     *
+     * Example: If input string is "This is the page title: {page:title}" then the part, '{page:title}', will be substituted with
+     * the current pages title field value.
      *
      * @param string $str Input value
      * @return string Processed input value
@@ -3295,6 +3300,12 @@ class ContentObjectRenderer
                 $len = strcspn(substr($str, $pointer), '{');
                 $newVal .= substr($str, $pointer, $len);
                 $inside = true;
+                if (substr($str, $pointer + $len + 1, 1) === '#') {
+                    $len2 = strcspn(substr($str, $pointer + $len), '}');
+                    $newVal .= substr($str, $pointer + $len, $len2);
+                    $len += $len2;
+                    $inside = false;
+                }
             } else {
                 $len = strcspn(substr($str, $pointer), '}') + 1;
                 $newVal .= $this->getData(substr($str, $pointer + 1, $len - 2), $this->data);
index ec54c04..b8ed108 100644 (file)
@@ -5629,6 +5629,33 @@ class ContentObjectRendererTest extends \TYPO3\TestingFramework\Core\Unit\UnitTe
     }
 
     /**
+     * Data provider for stdWrap_insertData
+     *
+     * @return array [$expect, $content]
+     */
+    public function stdWrap_insertDataProvider()
+    {
+        return [
+            'empty' => ['', ''],
+            'notFoundData' => ['any=1', 'any{$string}=1'],
+            'queryParameter' => ['any{#string}=1', 'any{#string}=1'],
+        ];
+    }
+
+    /**
+     * Check that stdWrap_insertData works properly with given input.
+     *
+     * @test
+     * @dataProvider stdWrap_insertDataProvider
+     * @param int $expect The expected output.
+     * @param string $content The given input.
+     */
+    public function stdWrap_insertDataAndInputExamples($expect, $content)
+    {
+        $this->assertSame($expect, $this->subject->stdWrap_insertData($content));
+    }
+
+    /**
      * Data provider for stdWrap_intval
      *
      * @return array [$expect, $content]