diff --git a/core/modules/ckeditor5/src/HTMLRestrictions.php b/core/modules/ckeditor5/src/HTMLRestrictions.php index 93e55b86a5036ab3e9361a43bbad2e631b21c8a1..4057271530be61279290e1f5beed2f065ffcbdc3 100644 --- a/core/modules/ckeditor5/src/HTMLRestrictions.php +++ b/core/modules/ckeditor5/src/HTMLRestrictions.php @@ -340,6 +340,14 @@ private static function fromObjectWithHtmlRestrictions(object $object): HTMLRest $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 @@ public static function fromString(string $elements_string): 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); } diff --git a/core/modules/ckeditor5/tests/src/Unit/HTMLRestrictionsTest.php b/core/modules/ckeditor5/tests/src/Unit/HTMLRestrictionsTest.php index 11f2a3bedd970737750c714a7a2b8ecdeabd3a62..4ba7fb590f406f547cc639d9fa75a9f9d3b2cf0c 100644 --- a/core/modules/ckeditor5/tests/src/Unit/HTMLRestrictionsTest.php +++ b/core/modules/ckeditor5/tests/src/Unit/HTMLRestrictionsTest.php @@ -816,6 +816,20 @@ public function providerOperands(): \Generator { '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>' => [ diff --git a/core/modules/filter/src/Plugin/Filter/FilterHtml.php b/core/modules/filter/src/Plugin/Filter/FilterHtml.php index 471e0b2f33c75a94f8ffd457166de2efd54cd42c..1db9d1c761229c8937a151ccf6827aad3deabcf1 100644 --- a/core/modules/filter/src/Plugin/Filter/FilterHtml.php +++ b/core/modules/filter/src/Plugin/Filter/FilterHtml.php @@ -267,13 +267,6 @@ public function getHTMLRestrictions() { } $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] = []; diff --git a/core/modules/filter/tests/src/Kernel/FilterAPITest.php b/core/modules/filter/tests/src/Kernel/FilterAPITest.php index 78a9977d1f8da7754429d7c9379ac43f136872c0..204ba859e329f261240fb33a9c8b981a31894cf8 100644 --- a/core/modules/filter/tests/src/Kernel/FilterAPITest.php +++ b/core/modules/filter/tests/src/Kernel/FilterAPITest.php @@ -206,7 +206,7 @@ public function testFilterFormatAPI() { '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 @@ public function testFilterFormatAPI() { '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]], ], ],