@allowed_tag_name is not supported.', ['@allowed_tag_name' => new HtmlEscapedText(reset($matches[0]))]),
+ $this->t('The wildcard tags @allowed_tag_names are not supported.', ['@allowed_tag_names' => new HtmlEscapedText(implode(' ', $matches[0]))])
+ ));
+ }
+ }
+
/**
* {@inheritdoc}
*/
@@ -278,6 +300,12 @@ public function setTextMode($textMode, $untilTag = NULL) {
$xpath = new \DOMXPath($dom);
foreach ($xpath->query('//body//*') as $node) {
$tag = $node->tagName;
+ // Skip wildcard tags: those are not allowed. Config cannot be trusted to
+ // have been validated.
+ // @see ::validateNoWildcardTag()
+ if (strpos($tag, $star_protector) !== FALSE) {
+ continue;
+ }
// All attributes are already allowed on this tag, this is the most
// permissive configuration, no additional processing is required.
diff --git a/core/modules/filter/tests/src/Functional/FilterAdminTest.php b/core/modules/filter/tests/src/Functional/FilterAdminTest.php
index 7d2cf73a04..7d6de080e3 100644
--- a/core/modules/filter/tests/src/Functional/FilterAdminTest.php
+++ b/core/modules/filter/tests/src/Functional/FilterAdminTest.php
@@ -382,6 +382,32 @@ public function testUrlFilterAdmin() {
$this->assertSession()->statusMessageNotContains('The text format Basic HTML has been updated.');
}
+ /**
+ * Tests the HTML filter settings form is properly validated.
+ */
+ public function testHtmlFilterAdmin() {
+ $selector = 'filters[filter_html][settings][allowed_html]';
+
+ $this->drupalGet('admin/config/content/formats/manage/basic_html');
+ $page = $this->getSession()->getPage();
+ $original_value = $page->findField($selector)->getValue();
+
+ // Assert validation error when trying to allow `<*>`.
+ $page->fillField($selector, $original_value . ' <*>');
+ $page->findButton('Save configuration')->click();
+ $this->assertSession()->statusMessageContains('The wildcard tag <*> is not supported.', 'error');
+
+ // Assert validation error when trying to allow `<*> ', $filter->getConfiguration()['settings']['allowed_html']); } + /** + * @covers ::getHTMLRestrictions + * @dataProvider providerGetHtmlRestrictions + */ + public function testGetHtmlRestrictions(string $allowed_html, array $expected_html_restrictions) { + $filter = new FilterHtml(['settings' => ['allowed_html' => $allowed_html]], 'filter_html', ['provider' => 'test']); + $this->assertSame($expected_html_restrictions, $filter->getHTMLRestrictions()); + } + + /** + * @return \Generator + */ + public function providerGetHtmlRestrictions() { + $hardcoded_asterisk_restrictions = [ + 'style' => FALSE, + 'on*' => FALSE, + 'lang' => TRUE, + 'dir' => [ + 'ltr' => TRUE, + 'rtl' => TRUE, + ], + ]; + + yield 'no allowed tags' => [ + '', + [ + 'allowed' => [ + '*' => $hardcoded_asterisk_restrictions, + ], + ], + ]; + + yield '
' => [
+ '
',
+ [
+ 'allowed' => [
+ 'p' => FALSE,
+ 'br' => FALSE,
+ '*' => $hardcoded_asterisk_restrictions,
+ ],
+ ],
+ ];
+
+ yield '
' => [
+ '
',
+ [
+ 'allowed' => [
+ 'p' => [
+ 'class' => TRUE,
+ ],
+ 'br' => FALSE,
+ '*' => $hardcoded_asterisk_restrictions,
+ ],
+ ],
+ ];
+
+ yield '