Issue #3268983 by nod_, iSoLate, plach, Wim Leers, acbramley, larowlan, scott_euser, catch: [regression] FilterHtml throws Unsupported operand types error when * used in tag attribute

merge-requests/2103/head
Lauri Eskola 2022-07-14 12:56:27 +03:00
parent f5d4496eef
commit c78d1a8987
No known key found for this signature in database
GPG Key ID: 382FC0F5B0DF53F8
4 changed files with 32 additions and 8 deletions

View File

@ -340,6 +340,14 @@ final class HTMLRestrictions {
$restrictions = $object->getHTMLRestrictions();
$allowed = $restrictions['allowed'];
// When allowing all tags on an attribute, transform FilterHtml output from
// ['tag' => ['*'=> TRUE]] to ['tag' => TRUE]
foreach ($allowed as $element => $attributes) {
if (is_array($attributes) && isset($attributes['*']) && $attributes['*'] === TRUE) {
$allowed[$element] = TRUE;
}
}
return new self($allowed);
}
@ -390,6 +398,14 @@ final class HTMLRestrictions {
}
}
// When allowing all tags on an attribute, transform FilterHtml output from
// ['tag' => ['*'=> TRUE]] to ['tag' => TRUE]
foreach ($allowed_elements as $element => $attributes) {
if (is_array($attributes) && isset($attributes['*']) && $attributes['*'] === TRUE) {
$allowed_elements[$element] = TRUE;
}
}
return new self($allowed_elements);
}

View File

@ -816,6 +816,20 @@ class HTMLRestrictionsTest extends UnitTestCase {
'intersection' => 'a',
'union' => 'b',
];
yield 'wildcard + matching tag: wildcard resolves into matching tag, but matching tag already supports all attributes' => [
'a' => new HTMLRestrictions(['p' => TRUE]),
'b' => new HTMLRestrictions(['$text-container' => ['class' => ['foo' => TRUE, 'bar' => TRUE]]]),
'diff' => 'a',
'intersection' => HTMLRestrictions::emptySet(),
'union' => new HTMLRestrictions(['p' => TRUE, '$text-container' => ['class' => ['foo' => TRUE, 'bar' => TRUE]]]),
];
yield 'wildcard + matching tag: wildcard resolves into matching tag, but matching tag already supports all attributes — vice versa' => [
'a' => new HTMLRestrictions(['$text-container' => ['class' => ['foo' => TRUE, 'bar' => TRUE]]]),
'b' => new HTMLRestrictions(['p' => TRUE]),
'diff' => 'a',
'intersection' => HTMLRestrictions::emptySet(),
'union' => new HTMLRestrictions(['p' => TRUE, '$text-container' => ['class' => ['foo' => TRUE, 'bar' => TRUE]]]),
];
// Tag restrictions.
yield 'tag restrictions are different: <a> vs <b c>' => [

View File

@ -267,13 +267,6 @@ class FilterHtml extends FilterBase {
}
$tag = $node->tagName;
if ($node->hasAttributes()) {
// This tag has a notation like "<foo *>", to indicate all attributes
// are allowed.
if ($node->hasAttribute($star_protector)) {
$restrictions['allowed'][$tag] = TRUE;
continue;
}
// Mark the tag as allowed, assigning TRUE for each attribute name if
// all values are allowed, or an array of specific allowed values.
$restrictions['allowed'][$tag] = [];

View File

@ -206,7 +206,7 @@ class FilterAPITest extends EntityKernelTestBase {
'filter_html' => [
'status' => 1,
'settings' => [
'allowed_html' => '<a> <b class> <c class="*"> <d class="foo bar-* *">',
'allowed_html' => '<a> <b class> <c class="*"> <d class="foo bar-* *"> <e *>',
],
],
],
@ -220,6 +220,7 @@ class FilterAPITest extends EntityKernelTestBase {
'b' => ['class' => TRUE],
'c' => ['class' => TRUE],
'd' => ['class' => ['foo' => TRUE, 'bar-*' => TRUE]],
'e' => ['*' => TRUE],
'*' => ['style' => FALSE, 'on*' => FALSE, 'lang' => TRUE, 'dir' => ['ltr' => TRUE, 'rtl' => TRUE]],
],
],