[BUGFIX] Respect TypoScript code after not matched include 67/51967/2
authorHelmut Hummel <typo3@helhum.io>
Mon, 6 Mar 2017 11:30:46 +0000 (12:30 +0100)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Mon, 6 Mar 2017 20:30:35 +0000 (21:30 +0100)
When parsing TypoScript with <INCLUDE which has a condition,
following TypoScript code which is not in an <INCLUDE statement
will be discarded.

Before early returning from a non matched condition, this
code needs to be added.

Resolves: #80150
Releases: master, 7.6
Change-Id: I4ea839012c57e5e7945dde3705aa96839afc58a0
Reviewed-on: https://review.typo3.org/51967
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/core/Classes/TypoScript/Parser/TypoScriptParser.php
typo3/sysext/core/Tests/Unit/TypoScript/Parser/TypoScriptParserTest.php

index 5aad2d2..f99aeee 100644 (file)
@@ -842,8 +842,9 @@ class TypoScriptParser
                     }
                     /** @var ConditionMatcher $conditionMatcher */
                     $conditionMatcher = GeneralUtility::makeInstance(ConditionMatcher::class);
-                    // If it didn't match then proceed to the next include
+                    // If it didn't match then proceed to the next include, but prepend next normal (not file) part to output string
                     if (!$conditionMatcher->match($condition)) {
+                        $newString .= $tsContentsTillNextInclude . LF;
                         continue;
                     }
                 }
index 42e28b2..ef93084 100644 (file)
@@ -14,6 +14,8 @@ namespace TYPO3\CMS\Core\Tests\Unit\TypoScript\Parser;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser;
+
 /**
  * Test case for \TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser
  */
@@ -262,6 +264,38 @@ class TypoScriptParserTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
     }
 
     /**
+     * @return array
+     */
+    public function includeFileDataProvider()
+    {
+        return [
+            'TS code before not matching include' => [
+                '
+                foo = bar
+                <INCLUDE_TYPOSCRIPT: source="FILE:dev.ts" condition="applicationContext = /^NotMatched/">
+                '
+            ],
+            'TS code after not matching include' => [
+                '
+                <INCLUDE_TYPOSCRIPT: source="FILE:dev.ts" condition="applicationContext = /^NotMatched/">
+                foo = bar
+                '
+            ],
+        ];
+    }
+
+    /**
+     * @test
+     * @dataProvider includeFileDataProvider
+     */
+    public function includeFilesWithConditions($typoScript)
+    {
+        $resolvedIncludeLines = TypoScriptParser::checkIncludeLines($typoScript);
+        $this->assertContains('foo = bar', $resolvedIncludeLines);
+        $this->assertNotContains('INCLUDE_TYPOSCRIPT', $resolvedIncludeLines);
+    }
+
+    /**
      * @param string $typoScript
      * @param array $expected
      * @dataProvider typoScriptIsParsedToArrayDataProvider
@@ -786,4 +820,4 @@ class TypoScriptParserTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
             ]
         ];
     }
-}
+}
\ No newline at end of file