Skip to content

Commit

Permalink
[TASK] Make RteHtmlParserTest notice free
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
lsascha authored and lolli42 committed Mar 17, 2018
1 parent 88706b7 commit f4184f5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 35 deletions.
18 changes: 9 additions & 9 deletions typo3/sysext/core/Classes/Html/HtmlParser.php
Expand Up @@ -861,10 +861,10 @@ public function compileTagAttribs($tagAttrib, $meta = [])
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') {
Expand Down Expand Up @@ -908,7 +908,7 @@ public function HTMLparserConfig($TSconfig, $keepTags = [])
}
}
// LocalNesting
if ($TSconfig['localNesting']) {
if (!empty($TSconfig['localNesting'])) {
$lN = GeneralUtility::trimExplode(',', strtolower($TSconfig['localNesting']), true);
foreach ($lN as $tn) {
if (isset($keepTags[$tn])) {
Expand All @@ -919,7 +919,7 @@ public function HTMLparserConfig($TSconfig, $keepTags = [])
}
}
}
if ($TSconfig['globalNesting']) {
if (!empty($TSconfig['globalNesting'])) {
$lN = GeneralUtility::trimExplode(',', strtolower($TSconfig['globalNesting']), true);
foreach ($lN as $tn) {
if (isset($keepTags[$tn])) {
Expand All @@ -930,7 +930,7 @@ public function HTMLparserConfig($TSconfig, $keepTags = [])
}
}
}
if ($TSconfig['rmTagIfNoAttrib']) {
if (!empty($TSconfig['rmTagIfNoAttrib'])) {
$lN = GeneralUtility::trimExplode(',', strtolower($TSconfig['rmTagIfNoAttrib']), true);
foreach ($lN as $tn) {
if (isset($keepTags[$tn])) {
Expand All @@ -944,7 +944,7 @@ public function HTMLparserConfig($TSconfig, $keepTags = [])
}
}
}
if ($TSconfig['noAttrib']) {
if (!empty($TSconfig['noAttrib'])) {
$lN = GeneralUtility::trimExplode(',', strtolower($TSconfig['noAttrib']), true);
foreach ($lN as $tn) {
if (isset($keepTags[$tn])) {
Expand All @@ -955,7 +955,7 @@ public function HTMLparserConfig($TSconfig, $keepTags = [])
}
}
}
if ($TSconfig['removeTags']) {
if (!empty($TSconfig['removeTags'])) {
$lN = GeneralUtility::trimExplode(',', strtolower($TSconfig['removeTags']), true);
foreach ($lN as $tn) {
$keepTags[$tn] = [];
Expand All @@ -973,8 +973,8 @@ public function HTMLparserConfig($TSconfig, $keepTags = [])
}
return [
$keepTags,
'' . $TSconfig['keepNonMatchedTags'],
(int)$TSconfig['htmlSpecialChars'],
'' . ($TSconfig['keepNonMatchedTags'] ?? ''),
(int)($TSconfig['htmlSpecialChars'] ?? 0),
$addConfig
];
}
Expand Down
36 changes: 18 additions & 18 deletions typo3/sysext/core/Classes/Html/RteHtmlParser.php
Expand Up @@ -169,11 +169,11 @@ public function RTE_transform($value, $_ = null, $direction = 'rte', $thisConfig
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'];
}

Expand Down Expand Up @@ -209,8 +209,8 @@ public function RTE_transform($value, $_ = null, $direction = 'rte', $thisConfig
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);
Expand Down Expand Up @@ -239,8 +239,8 @@ public function RTE_transform($value, $_ = null, $direction = 'rte', $thisConfig
}
} 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 {
Expand Down Expand Up @@ -311,7 +311,7 @@ protected function resolveAppliedTransformationModes(string $direction, array $m
*/
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);
}
Expand Down Expand Up @@ -787,7 +787,7 @@ public function TS_transform_rte($value)
$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])) {
Expand Down Expand Up @@ -829,7 +829,7 @@ public function HTMLcleaner_db($content)
{
$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);
}

Expand All @@ -843,18 +843,18 @@ public function HTMLcleaner_db($content)
*/
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]);
}
Expand All @@ -863,7 +863,7 @@ public function getKeepTags($direction = 'rte')
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:
Expand All @@ -882,11 +882,11 @@ public function getKeepTags($direction = 'rte')
}
}
// 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:
Expand Down Expand Up @@ -1023,7 +1023,7 @@ protected function processContentWithinParagraph(string $content, string $fullCo
$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)) {
Expand Down
15 changes: 7 additions & 8 deletions typo3/sysext/core/Tests/Unit/Html/RteHtmlParserTest.php
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace TYPO3\CMS\Core\Tests\Unit\Html;

/*
Expand All @@ -14,27 +15,25 @@
* 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
*/
protected $subject = null;

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',
];
}

Expand Down

0 comments on commit f4184f5

Please sign in to comment.