Issue #3268983 by nod_, iSoLate, plach, Wim Leers, acbramley, larowlan, scott_euser: [regression] FilterHtml throws Unsupported operand types error when * used in tag attribute
parent
c9770654cc
commit
afc9c24e30
|
@ -347,6 +347,14 @@ final class HTMLRestrictions {
|
|||
throw new \DomainException('text formats with only filters that forbid tags rather than allowing tags are not yet supported.');
|
||||
}
|
||||
|
||||
// When allowing all tags on an attribute, transform FilterHtml output from
|
||||
// ['tag' => ['*'=> TRUE]] to ['tag' => TRUE]
|
||||
foreach ($restrictions['allowed'] as $element => $attributes) {
|
||||
if (is_array($attributes) && isset($attributes['*']) && $attributes['*'] === TRUE) {
|
||||
$restrictions['allowed'][$element] = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
$allowed = $restrictions['allowed'];
|
||||
|
||||
return new self($allowed);
|
||||
|
@ -399,6 +407,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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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>' => [
|
||||
|
|
|
@ -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] = [];
|
||||
|
|
|
@ -203,7 +203,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 *>',
|
||||
],
|
||||
],
|
||||
],
|
||||
|
@ -217,6 +217,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]],
|
||||
],
|
||||
],
|
||||
|
|
Loading…
Reference in New Issue