From f4184f59cbc70d8fe46dcf312f1a03b931fa3423 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sascha=20L=C3=B6ffler?= <lsascha@gmail.com>
Date: Sat, 17 Mar 2018 11:05:50 +0100
Subject: [PATCH] [TASK] Make RteHtmlParserTest notice free

Resolves: #84393
Releases: master
Change-Id: Ia39128297b7fdd457ced11d123a1763202a9d219
Reviewed-on: https://review.typo3.org/56282
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
---
 typo3/sysext/core/Classes/Html/HtmlParser.php | 18 +++++-----
 .../core/Classes/Html/RteHtmlParser.php       | 36 +++++++++----------
 .../Tests/Unit/Html/RteHtmlParserTest.php     | 15 ++++----
 3 files changed, 34 insertions(+), 35 deletions(-)

diff --git a/typo3/sysext/core/Classes/Html/HtmlParser.php b/typo3/sysext/core/Classes/Html/HtmlParser.php
index 17be2550d6fb..9141f01738e0 100644
--- a/typo3/sysext/core/Classes/Html/HtmlParser.php
+++ b/typo3/sysext/core/Classes/Html/HtmlParser.php
@@ -861,10 +861,10 @@ class HtmlParser
     public function HTMLparserConfig($TSconfig, $keepTags = [])
     {
         // Allow tags (base list, merged with incoming array)
-        $alTags = array_flip(GeneralUtility::trimExplode(',', strtolower($TSconfig['allowTags']), true));
+        $alTags = array_flip(GeneralUtility::trimExplode(',', strtolower($TSconfig['allowTags'] ?? ''), true));
         $keepTags = array_merge($alTags, $keepTags);
         // Set config properties.
-        if (is_array($TSconfig['tags.'])) {
+        if (isset($TSconfig['tags.']) && is_array($TSconfig['tags.'])) {
             foreach ($TSconfig['tags.'] as $key => $tagC) {
                 if (!is_array($tagC) && $key == strtolower($key)) {
                     if ((string)$tagC === '0') {
@@ -908,7 +908,7 @@ class HtmlParser
             }
         }
         // LocalNesting
-        if ($TSconfig['localNesting']) {
+        if (!empty($TSconfig['localNesting'])) {
             $lN = GeneralUtility::trimExplode(',', strtolower($TSconfig['localNesting']), true);
             foreach ($lN as $tn) {
                 if (isset($keepTags[$tn])) {
@@ -919,7 +919,7 @@ class HtmlParser
                 }
             }
         }
-        if ($TSconfig['globalNesting']) {
+        if (!empty($TSconfig['globalNesting'])) {
             $lN = GeneralUtility::trimExplode(',', strtolower($TSconfig['globalNesting']), true);
             foreach ($lN as $tn) {
                 if (isset($keepTags[$tn])) {
@@ -930,7 +930,7 @@ class HtmlParser
                 }
             }
         }
-        if ($TSconfig['rmTagIfNoAttrib']) {
+        if (!empty($TSconfig['rmTagIfNoAttrib'])) {
             $lN = GeneralUtility::trimExplode(',', strtolower($TSconfig['rmTagIfNoAttrib']), true);
             foreach ($lN as $tn) {
                 if (isset($keepTags[$tn])) {
@@ -944,7 +944,7 @@ class HtmlParser
                 }
             }
         }
-        if ($TSconfig['noAttrib']) {
+        if (!empty($TSconfig['noAttrib'])) {
             $lN = GeneralUtility::trimExplode(',', strtolower($TSconfig['noAttrib']), true);
             foreach ($lN as $tn) {
                 if (isset($keepTags[$tn])) {
@@ -955,7 +955,7 @@ class HtmlParser
                 }
             }
         }
-        if ($TSconfig['removeTags']) {
+        if (!empty($TSconfig['removeTags'])) {
             $lN = GeneralUtility::trimExplode(',', strtolower($TSconfig['removeTags']), true);
             foreach ($lN as $tn) {
                 $keepTags[$tn] = [];
@@ -973,8 +973,8 @@ class HtmlParser
         }
         return [
             $keepTags,
-            '' . $TSconfig['keepNonMatchedTags'],
-            (int)$TSconfig['htmlSpecialChars'],
+            '' . ($TSconfig['keepNonMatchedTags'] ?? ''),
+            (int)($TSconfig['htmlSpecialChars'] ?? 0),
             $addConfig
         ];
     }
diff --git a/typo3/sysext/core/Classes/Html/RteHtmlParser.php b/typo3/sysext/core/Classes/Html/RteHtmlParser.php
index 03e97ce7ca0b..d682cdda7e63 100644
--- a/typo3/sysext/core/Classes/Html/RteHtmlParser.php
+++ b/typo3/sysext/core/Classes/Html/RteHtmlParser.php
@@ -169,11 +169,11 @@ class RteHtmlParser extends HtmlParser implements LoggerAwareInterface
         if (isset($this->procOptions['allowedClasses.'])) {
             $this->allowedClasses = (array)$this->procOptions['allowedClasses.'];
         } else {
-            $this->allowedClasses = GeneralUtility::trimExplode(',', $this->procOptions['allowedClasses'], true);
+            $this->allowedClasses = GeneralUtility::trimExplode(',', $this->procOptions['allowedClasses'] ?? '', true);
         }
 
         // Dynamic configuration of blockElementList
-        if ($this->procOptions['blockElementList']) {
+        if (!empty($this->procOptions['blockElementList'])) {
             $this->blockElementList = $this->procOptions['blockElementList'];
         }
 
@@ -209,8 +209,8 @@ class RteHtmlParser extends HtmlParser implements LoggerAwareInterface
         foreach ($modes as $cmd) {
             if ($direction === 'db') {
                 // Checking for user defined transformation:
-                if ($className = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_parsehtml_proc.php']['transformation'][$cmd]) {
-                    $_procObj = GeneralUtility::makeInstance($className);
+                if (!empty($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_parsehtml_proc.php']['transformation'][$cmd])) {
+                    $_procObj = GeneralUtility::makeInstance($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_parsehtml_proc.php']['transformation'][$cmd]);
                     $_procObj->pObj = $this;
                     $_procObj->transformationKey = $cmd;
                     $value = $_procObj->transform_db($value, $this);
@@ -239,8 +239,8 @@ class RteHtmlParser extends HtmlParser implements LoggerAwareInterface
                 }
             } elseif ($direction === 'rte') {
                 // Checking for user defined transformation:
-                if ($className = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_parsehtml_proc.php']['transformation'][$cmd]) {
-                    $_procObj = GeneralUtility::makeInstance($className);
+                if (!empty($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_parsehtml_proc.php']['transformation'][$cmd])) {
+                    $_procObj = GeneralUtility::makeInstance($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_parsehtml_proc.php']['transformation'][$cmd]);
                     $_procObj->pObj = $this;
                     $value = $_procObj->transform_rte($value, $this);
                 } else {
@@ -311,7 +311,7 @@ class RteHtmlParser extends HtmlParser implements LoggerAwareInterface
      */
     protected function runHtmlParserIfConfigured($content, $configurationDirective)
     {
-        if ($this->procOptions[$configurationDirective]) {
+        if (!empty($this->procOptions[$configurationDirective])) {
             list($keepTags, $keepNonMatchedTags, $hscMode, $additionalConfiguration) = $this->HTMLparserConfig($this->procOptions[$configurationDirective . '.']);
             $content = $this->HTMLcleaner($content, $keepTags, $keepNonMatchedTags, $hscMode, $additionalConfiguration);
         }
@@ -787,7 +787,7 @@ class RteHtmlParser extends HtmlParser implements LoggerAwareInterface
                 $blockSplit[$k + 1] = preg_replace('/^[ ]*' . LF . '/', '', $blockSplit[$k + 1]);
             } else {
                 // NON-block:
-                $nextFTN = $this->getFirstTagName($blockSplit[$k + 1]);
+                $nextFTN = $this->getFirstTagName($blockSplit[$k + 1] ?? '');
                 $onlyLineBreaks = (preg_match('/^[ ]*' . LF . '+[ ]*$/', $blockSplit[$k]) == 1);
                 // If the line is followed by a block or is the last line:
                 if (GeneralUtility::inList($this->blockElementList, $nextFTN) || !isset($blockSplit[$k + 1])) {
@@ -829,7 +829,7 @@ class RteHtmlParser extends HtmlParser implements LoggerAwareInterface
     {
         $keepTags = $this->getKeepTags('db');
         // Default: remove unknown tags.
-        $keepUnknownTags = (bool)$this->procOptions['dontRemoveUnknownTags_db'];
+        $keepUnknownTags = (bool)($this->procOptions['dontRemoveUnknownTags_db'] ?? false);
         return $this->HTMLcleaner($content, $keepTags, $keepUnknownTags);
     }
 
@@ -843,18 +843,18 @@ class RteHtmlParser extends HtmlParser implements LoggerAwareInterface
      */
     public function getKeepTags($direction = 'rte')
     {
-        if (!is_array($this->getKeepTags_cache[$direction])) {
+        if (!isset($this->getKeepTags_cache[$direction]) || !is_array($this->getKeepTags_cache[$direction])) {
             // Setting up allowed tags:
             // Default is to get allowed/denied tags from internal array of processing options:
             // Construct default list of tags to keep:
-            if (is_array($this->procOptions['allowTags.'])) {
+            if (isset($this->procOptions['allowTags.']) && is_array($this->procOptions['allowTags.'])) {
                 $keepTags = implode(',', $this->procOptions['allowTags.']);
             } else {
-                $keepTags = $this->procOptions['allowTags'];
+                $keepTags = $this->procOptions['allowTags'] ?? '';
             }
             $keepTags = array_flip(GeneralUtility::trimExplode(',', $this->defaultAllowedTagsList . ',' . strtolower($keepTags), true));
             // For tags to deny, remove them from $keepTags array:
-            $denyTags = GeneralUtility::trimExplode(',', $this->procOptions['denyTags'], true);
+            $denyTags = GeneralUtility::trimExplode(',', $this->procOptions['denyTags'] ?? '', true);
             foreach ($denyTags as $dKe) {
                 unset($keepTags[$dKe]);
             }
@@ -863,7 +863,7 @@ class RteHtmlParser extends HtmlParser implements LoggerAwareInterface
                 case 'rte':
                     // Transforming keepTags array so it can be understood by the HTMLcleaner function.
                     // This basically converts the format of the array from TypoScript (having dots) to plain multi-dimensional array.
-                    list($keepTags) = $this->HTMLparserConfig($this->procOptions['HTMLparser_rte.'], $keepTags);
+                    list($keepTags) = $this->HTMLparserConfig($this->procOptions['HTMLparser_rte.'] ?? [], $keepTags);
                     break;
                 case 'db':
                     // Setting up span tags if they are allowed:
@@ -882,11 +882,11 @@ class RteHtmlParser extends HtmlParser implements LoggerAwareInterface
                         }
                     }
                     // Setting further options, getting them from the processing options
-                    $TSc = $this->procOptions['HTMLparser_db.'];
-                    if (!$TSc['globalNesting']) {
+                    $TSc = $this->procOptions['HTMLparser_db.'] ?? [];
+                    if (empty($TSc['globalNesting'])) {
                         $TSc['globalNesting'] = 'b,i,u,a,center,font,sub,sup,strong,em,strike,span';
                     }
-                    if (!$TSc['noAttrib']) {
+                    if (empty($TSc['noAttrib'])) {
                         $TSc['noAttrib'] = 'b,i,u,br,center,hr,sub,sup,strong,em,li,ul,ol,blockquote,strike';
                     }
                     // Transforming the array from TypoScript to regular array:
@@ -1023,7 +1023,7 @@ class RteHtmlParser extends HtmlParser implements LoggerAwareInterface
             $tagAttributes = array_intersect_key($tagAttributes, array_flip($this->allowedAttributesForParagraphTags));
 
             // Only allow classes that are whitelisted in $this->allowedClasses
-            if (trim($tagAttributes['class']) !== '' && !empty($this->allowedClasses) && !in_array($tagAttributes['class'], $this->allowedClasses, true)) {
+            if (isset($tagAttributes['class']) && trim($tagAttributes['class']) !== '' && !empty($this->allowedClasses) && !in_array($tagAttributes['class'], $this->allowedClasses, true)) {
                 $classes = GeneralUtility::trimExplode(' ', $tagAttributes['class'], true);
                 $classes = array_intersect($classes, $this->allowedClasses);
                 if (!empty($classes)) {
diff --git a/typo3/sysext/core/Tests/Unit/Html/RteHtmlParserTest.php b/typo3/sysext/core/Tests/Unit/Html/RteHtmlParserTest.php
index 9567823e8ecf..d11c8d270a4e 100644
--- a/typo3/sysext/core/Tests/Unit/Html/RteHtmlParserTest.php
+++ b/typo3/sysext/core/Tests/Unit/Html/RteHtmlParserTest.php
@@ -1,4 +1,5 @@
 <?php
+declare(strict_types=1);
 namespace TYPO3\CMS\Core\Tests\Unit\Html;
 
 /*
@@ -14,16 +15,14 @@ namespace TYPO3\CMS\Core\Tests\Unit\Html;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Html\RteHtmlParser;
+use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
+
 /**
  * Testcase for \TYPO3\CMS\Core\Html\RteHtmlParser
  */
-class RteHtmlParserTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
+class RteHtmlParserTest extends UnitTestCase
 {
-    /**
-     * Subject is not notice free, disable E_NOTICES
-     */
-    protected static $suppressNotices = true;
-
     /**
      * @var \TYPO3\CMS\Core\Html\RteHtmlParser
      */
@@ -31,10 +30,10 @@ class RteHtmlParserTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
 
     protected function setUp()
     {
-        $this->subject = new \TYPO3\CMS\Core\Html\RteHtmlParser();
+        $this->subject = new RteHtmlParser();
         $this->subject->procOptions = [
             'allowTagsOutside' => 'hr, address',
-            'overruleMode' => 'default'
+            'overruleMode' => 'default',
         ];
     }
 
-- 
GitLab