diff --git a/core/lib/Drupal/Component/Utility/Xss.php b/core/lib/Drupal/Component/Utility/Xss.php index ddce1799b462d0bd3f1c733cc13cae608146d5b4..7a771822aa3ae4a2ecdffb2dbb03b11b387f49e8 100644 --- a/core/lib/Drupal/Component/Utility/Xss.php +++ b/core/lib/Drupal/Component/Utility/Xss.php @@ -152,7 +152,7 @@ protected static function split($string, $html_tags, $split_mode) { return '<'; } - if (!preg_match('%^<\s*(/\s*)?([a-zA-Z0-9]+)([^>]*)>?|()$%', $string, $matches)) { + if (!preg_match('%^<\s*(/\s*)?([a-zA-Z0-9\-]+)([^>]*)>?|()$%', $string, $matches)) { // Seriously malformed. return ''; } diff --git a/core/tests/Drupal/Tests/Component/Utility/XssTest.php b/core/tests/Drupal/Tests/Component/Utility/XssTest.php index a682fb1cc094f3cbf2ee2cf4943e73a4ea423de0..7f45b17323d88cd73f4e984b6dbe6606a1f8f00a 100644 --- a/core/tests/Drupal/Tests/Component/Utility/XssTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/XssTest.php @@ -59,11 +59,19 @@ protected function setUp() { * The expected result. * @param string $message * The assertion message to display upon failure. + * @param array $allowed_tags + * (optional) The allowed HTML tags to be passed to \Drupal\Component\Utility\Xss::filter(). * * @dataProvider providerTestFilterXssNormalized */ - public function testFilterXssNormalized($value, $expected, $message) { - $this->assertNormalized(Xss::filter($value), $expected, $message); + public function testFilterXssNormalized($value, $expected, $message, array $allowed_tags = NULL) { + if ($allowed_tags === NULL) { + $value = Xss::filter($value); + } + else { + $value = Xss::filter($value, $allowed_tags); + } + $this->assertNormalized($value, $expected, $message); } /** @@ -76,6 +84,8 @@ public function testFilterXssNormalized($value, $expected, $message) { * - The value to filter. * - The value to expect after filtering. * - The assertion message. + * - (optional) The allowed HTML HTML tags array that should be passed to + * \Drupal\Component\Utility\Xss::filter(). */ public function providerTestFilterXssNormalized() { return array( @@ -94,6 +104,13 @@ public function providerTestFilterXssNormalized() { "who&#039; online", 'HTML filter -- double encoded html entity number', ), + // Custom elements with dashes in the tag name. + array( + "", + "", + 'Custom element with dashes in tag name.', + array('test-element'), + ), ); }