Skip to content

Commit 5e7df67

Browse files
froemkengarvinhicking
authored andcommitted
[BUGFIX] Read RTE options as string and array
EXT:rte_ckeditor was introduced in TYPO3v8 with a configuration based on YAML. With this, most options were given in array format, but because of backwards compatibility to TSConfig, a lot of options are still also interpreted as string format. However, a few options were missing to be made compatible for both kinds of specification, either via YAML or TSConfig. Options like "keepTags", "denyTags", "range" and "list" (for `fixAttrib`) are now checked for string and array. Also, "always=1" is cast to string now to prevent error in `strtoupper()`. Converting all values of "list" array to upper case will now use `array_map` instead of `array_walk` to prevent calling `strtoupper` with wrong argument counts. The tests introduced with #106189 are now enabled to verify this fixed behaviour. Resolves: #92943 Related: #106189 Releases: main, 13.4 Change-Id: Ic362c6d4a283b13c0de12598d1a8b31e28ee7dff Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/85137 Tested-by: Benni Mack <benni@typo3.org> Reviewed-by: Benjamin Franzke <ben@bnf.dev> Tested-by: Garvin Hicking <gh@faktor-e.de> Reviewed-by: Benni Mack <benni@typo3.org> Tested-by: core-ci <typo3@b13.com> Reviewed-by: Garvin Hicking <gh@faktor-e.de>
1 parent 05399a3 commit 5e7df67

File tree

6 files changed

+68
-68
lines changed

6 files changed

+68
-68
lines changed

typo3/sysext/core/Classes/Html/HtmlParser.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -541,8 +541,8 @@ public function HTMLcleaner($content, $tags = [], $keepAll = 0, $hSC = 0, $addCo
541541
$normalizedSearchList = $params['list'];
542542
if (!($params['casesensitiveComp'] ?? false)) {
543543
// Case-sensitive comparison is not wanted, normalize all values
544-
$normalizedSearchWord = strtoupper($tagAttrib[0][$attr] ?? '');
545-
array_walk($normalizedSearchList, strtoupper(...));
544+
$normalizedSearchWord = strtoupper((string)($tagAttrib[0][$attr] ?? ''));
545+
$normalizedSearchList = array_map('strtoupper', $normalizedSearchList);
546546
}
547547
if (!in_array($normalizedSearchWord, $normalizedSearchList, true)) {
548548
$tagAttrib[0][$attr] = $params['list'][0];
@@ -889,11 +889,19 @@ public function HTMLparserConfig($TSconfig, $keepTags = [])
889889
$keepTags[$key]['fixAttrib'][$atName] = [];
890890
}
891891
$keepTags[$key]['fixAttrib'][$atName] = array_merge($keepTags[$key]['fixAttrib'][$atName], $atConfig);
892-
if ((string)($keepTags[$key]['fixAttrib'][$atName]['range'] ?? '') !== '') {
893-
$keepTags[$key]['fixAttrib'][$atName]['range'] = GeneralUtility::trimExplode(',', $keepTags[$key]['fixAttrib'][$atName]['range']);
892+
if (!empty($keepTags[$key]['fixAttrib'][$atName]['range'])) {
893+
if (!isset($keepTags[$key]['fixAttrib'][$atName]['range.'])) {
894+
$keepTags[$key]['fixAttrib'][$atName]['range'] = GeneralUtility::trimExplode(',', $keepTags[$key]['fixAttrib'][$atName]['range']);
895+
} else {
896+
$keepTags[$key]['fixAttrib'][$atName]['range'] = $keepTags[$key]['fixAttrib'][$atName]['range.'];
897+
}
894898
}
895-
if ((string)($keepTags[$key]['fixAttrib'][$atName]['list'] ?? '') !== '') {
896-
$keepTags[$key]['fixAttrib'][$atName]['list'] = GeneralUtility::trimExplode(',', $keepTags[$key]['fixAttrib'][$atName]['list']);
899+
if (!empty($keepTags[$key]['fixAttrib'][$atName]['list'])) {
900+
if (!isset($keepTags[$key]['fixAttrib'][$atName]['list.'])) {
901+
$keepTags[$key]['fixAttrib'][$atName]['list'] = GeneralUtility::trimExplode(',', $keepTags[$key]['fixAttrib'][$atName]['list']);
902+
} else {
903+
$keepTags[$key]['fixAttrib'][$atName]['list'] = $keepTags[$key]['fixAttrib'][$atName]['list.'];
904+
}
897905
}
898906
}
899907
}

typo3/sysext/core/Classes/Html/RteHtmlParser.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,13 @@ protected function setProcessingConfiguration(array $processingConfiguration): v
134134

135135
// Dynamic configuration of blockElementList
136136
if (!empty($this->procOptions['blockElementList'])) {
137-
$this->blockElementList = $this->procOptions['blockElementList'];
137+
if (!isset($this->procOptions['blockElementList.'])) {
138+
$blockElementList = GeneralUtility::trimExplode(',', $this->procOptions['blockElementList'], true);
139+
} else {
140+
$blockElementList = (array)$this->procOptions['blockElementList.'];
141+
}
142+
143+
$this->blockElementList = implode(',', $blockElementList);
138144
}
139145

140146
// Define which attributes are allowed on <p> tags
@@ -528,7 +534,11 @@ protected function getKeepTags(string $direction): array
528534
}
529535
$keepTags = array_flip(GeneralUtility::trimExplode(',', $this->defaultAllowedTagsList . ',' . strtolower($keepTags), true));
530536
// For tags to deny, remove them from $keepTags array:
531-
$denyTags = GeneralUtility::trimExplode(',', $this->procOptions['denyTags'] ?? '', true);
537+
if (!isset($this->procOptions['denyTags.'])) {
538+
$denyTags = GeneralUtility::trimExplode(',', $this->procOptions['denyTags'] ?? '', true);
539+
} else {
540+
$denyTags = $this->procOptions['denyTags.'];
541+
}
532542
foreach ($denyTags as $dKe) {
533543
unset($keepTags[$dKe]);
534544
}

typo3/sysext/core/Tests/Unit/Html/HtmlParserTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,6 @@ public static function fixAttribCanUseArrayAndStringNotationsDataProvider(): arr
258258
],
259259
],
260260
],
261-
/* @todo BROKEN until https://review.typo3.org/c/Packages/TYPO3.CMS/+/85137 is merged
262261
'data-custom, case insensitive' => [
263262
'content' => '<span data-custom=" bTn ">text</span>',
264263
'expectedResult' => '<span data-custom="bTn">text</span>',
@@ -299,7 +298,6 @@ public static function fixAttribCanUseArrayAndStringNotationsDataProvider(): arr
299298
],
300299
],
301300
],
302-
*/
303301
'data-custom3, case sensitive' => [
304302
'content' => '<span data-custom3=" bTn ">text</span>',
305303
'expectedResult' => '<span data-custom3="button">text</span>',

typo3/sysext/rte_ckeditor/Tests/Functional/Fixtures/RteConfigArrayFixtureProcessing.yaml

Lines changed: 24 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,88 +8,73 @@ processing:
88
allowAttributes: [class, id, data-custom, data-special]
99

1010
# 'blockElementList' has test coverage
11-
# @todo BROKEN until https://review.typo3.org/c/Packages/TYPO3.CMS/+/85137 is merged
12-
# blockElementList: [table, blockquote, ul]
13-
blockElementList: 'table,blockquote,ul'
11+
blockElementList: [table, blockquote, ul]
1412

1513
HTMLparser_db:
1614
noAttrib: br
17-
# @todo BROKEN until https://review.typo3.org/c/Packages/TYPO3.CMS/+/85137 is merged
18-
#denyTags: ['img', 'font']
19-
denyTags: 'img,font'
15+
denyTags: ['img', 'font']
2016
tags:
2117
# The following 'fixAttrib' cases have test coverage
2218
font:
2319
# Note, this here shall NOT apply due to denyTags above!
2420
fixAttrib:
2521
class:
2622
default: 'btn'
27-
# @todo BROKEN until https://review.typo3.org/c/Packages/TYPO3.CMS/+/85137 is merged
28-
#list: ['button','btn']
29-
list: 'button,btn'
23+
list: ['button','btn']
3024
a:
3125
fixAttrib:
3226
class:
3327
always: 1
3428
trim: 1,
3529
default: 'btn'
36-
# @todo BROKEN until https://review.typo3.org/c/Packages/TYPO3.CMS/+/85137 is merged
37-
#list: ['button','btn']
38-
list: 'button,btn'
39-
span:
40-
fixAttrib:
41-
# @todo BROKEN until https://review.typo3.org/c/Packages/TYPO3.CMS/+/85137 is merged
42-
#data-custom:
43-
# always: 0
44-
# trim: 1
45-
# default: btn
46-
# casesensitiveComp: 0
47-
# list: ['button','btn']
48-
#data-custom2:
49-
# always: 0,
50-
# trim: 1,
51-
# default: btn
52-
# casesensitiveComp: 0,
53-
# list: ['buTTon','bTn']
30+
list: ['button','btn']
31+
span1:
32+
fixAttrib:
33+
data-custom:
34+
always: 0
35+
trim: 1
36+
default: btn
37+
casesensitiveComp: 0
38+
list: ['button','btn']
39+
span2:
40+
fixAttrib:
41+
data-custom2:
42+
always: 0,
43+
trim: 1,
44+
default: btn
45+
casesensitiveComp: 0,
46+
list: ['buTTon','bTn']
5447
span3:
5548
fixAttrib:
5649
data-custom3:
5750
always: 0
5851
trim: 1
5952
default: btn
6053
casesensitiveComp: 1
61-
# @todo BROKEN until https://review.typo3.org/c/Packages/TYPO3.CMS/+/85137 is merged
62-
#list: ['button','btn']
63-
list: 'button,btn'
54+
list: ['button','btn']
6455
span4:
6556
fixAttrib:
6657
data-custom4:
6758
always: 0
6859
trim: 1
6960
default: 'bTn'
7061
casesensitiveComp: 1
71-
# @todo BROKEN until https://review.typo3.org/c/Packages/TYPO3.CMS/+/85137 is merged
72-
#list: ['buTTon','bTn']
73-
list: 'buTTon,bTn'
62+
list: ['buTTon','bTn']
7463
span5:
7564
fixAttrib:
7665
data-custom5:
7766
always: '0'
7867
trim: '1'
7968
casesensitiveComp: 1
80-
# @todo BROKEN until https://review.typo3.org/c/Packages/TYPO3.CMS/+/85137 is merged
81-
#range: ['0','3']
82-
range: '0,3'
69+
range: ['0','3']
8370
span6:
8471
fixAttrib:
8572
data-custom6:
8673
always: '0'
8774
trim: '1'
8875
default: 'bTn'
8976
casesensitiveComp: 1
90-
# @todo BROKEN until https://review.typo3.org/c/Packages/TYPO3.CMS/+/85137 is merged
91-
#range: ['2']
92-
range: '2'
77+
range: ['2']
9378
span7:
9479
fixAttrib:
9580
data-custom7:

typo3/sysext/rte_ckeditor/Tests/Functional/Fixtures/RteConfigStringFixtureProcessing.yaml

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,22 @@ processing:
4848
trim: 1,
4949
default: 'btn'
5050
list: 'button,btn'
51-
span:
52-
fixAttrib:
53-
# @todo BROKEN until https://review.typo3.org/c/Packages/TYPO3.CMS/+/85137 is merged
54-
#data-custom:
55-
# always: 0
56-
# trim: 1
57-
# default: btn
58-
# casesensitiveComp: 0
59-
# list: 'button,btn'
60-
#data-custom2:
61-
# always: 0,
62-
# trim: 1,
63-
# default: btn
64-
# casesensitiveComp: 0,
65-
# list: buTTon,bTn
51+
span1:
52+
fixAttrib:
53+
data-custom:
54+
always: 0
55+
trim: 1
56+
default: btn
57+
casesensitiveComp: 0
58+
list: 'button,btn'
59+
span2:
60+
fixAttrib:
61+
data-custom2:
62+
always: 0,
63+
trim: 1,
64+
default: btn
65+
casesensitiveComp: 0,
66+
list: 'buTTon,bTn'
6667
span3:
6768
fixAttrib:
6869
data-custom3:

typo3/sysext/rte_ckeditor/Tests/Functional/HtmlParser/HtmlParserProcessingTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,16 +206,14 @@ public static function HtmlParserProcessingParsesFixAttribsDataProvider(): array
206206
'expectedResult' => '<a class="btn">text</a><a class="button">text</a><a class="button">text</a><a class="btn">text</a>',
207207
],
208208
// This span enumberation is used to not need to create a distinct YAML file for each tag, as they would influence each other when all put onto "span".
209-
/* @todo BROKEN until https://review.typo3.org/c/Packages/TYPO3.CMS/+/85137 is merged
210209
'data-custom, case insensitive' => [
211210
'content' => '<span1 data-custom=" bTn ">text</span1>',
212211
'expectedResult' => '<span1 data-custom="bTn">text</span1>',
213212
],
214213
'data-custom, case insensitive in list' => [
215-
'content' => '<span2 data-custom2=" bTn ">text</span>',
216-
'expectedResult' => '<span2 data-custom2="bTn">text</span>',
214+
'content' => '<span2 data-custom2=" bTn ">text</span2>',
215+
'expectedResult' => '<span2 data-custom2="bTn">text</span2>',
217216
],
218-
*/
219217
'data-custom3, case sensitive' => [
220218
'content' => '<span3 data-custom3=" bTn ">text</span3>',
221219
'expectedResult' => '<span3 data-custom3="button">text</span3>',

0 commit comments

Comments
 (0)