[TASK] Inform user if TS condition does not make sense 35/56835/4
authorMarkus Klein <markus.klein@typo3.org>
Wed, 2 May 2018 22:23:05 +0000 (00:23 +0200)
committerGeorg Ringer <georg.ringer@gmail.com>
Thu, 3 May 2018 06:27:15 +0000 (08:27 +0200)
Empty conditions `[]` always evaluate to false. Warn the user
if such a condition is present.

Resolves: #84911
Releases: master, 8.7
Change-Id: I499e64aad30e29fe3698c40fed57e1f1c87ce885
Reviewed-on: https://review.typo3.org/56835
Reviewed-by: Robert Wildling <robertwildling@gmail.com>
Tested-by: Robert Wildling <robertwildling@gmail.com>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Riny van Tiggelen <info@online-gamer.nl>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
typo3/sysext/core/Classes/TypoScript/Parser/TypoScriptParser.php
typo3/sysext/core/Tests/Unit/TypoScript/Parser/TypoScriptParserTest.php

index f3aecc5..5fb7b92 100644 (file)
@@ -240,6 +240,10 @@ class TypoScriptParser
                 $this->error('Breakpoint at ' . ($this->lineNumberOffset + $this->rawP - 2) . ': Line content was "' . $this->raw[$this->rawP - 2] . '"', 1);
                 break;
             }
+            if ($pre === '[]') {
+                $this->error('Empty condition is always false, this does not make sense. At line ' . ($this->lineNumberOffset + $this->rawP - 1), 2);
+                break;
+            }
             $preUppercase = strtoupper($pre);
             if ($pre[0] === '[' &&
                 ($preUppercase === '[GLOBAL]' ||
index 7df1e6d..1cc1c53 100644 (file)
@@ -291,6 +291,20 @@ class TypoScriptParserTest extends UnitTestCase
     }
 
     /**
+     * @test
+     */
+    public function emptyConditionIsReported()
+    {
+        $timeTrackerProphecy = $this->prophesize(TimeTracker::class);
+        GeneralUtility::setSingletonInstance(TimeTracker::class, $timeTrackerProphecy->reveal());
+
+        $typoScript = '[]';
+        $this->typoScriptParser->parse($typoScript);
+        $expected = 'Empty condition is always false, this does not make sense. At line 0';
+        $this->assertEquals($expected, $this->typoScriptParser->errors[0][0]);
+    }
+
+    /**
      * @return array
      */
     public function doubleSlashCommentsDataProvider()