From 4484e2d2c3f4a5e1090c616413f64e34f9f5c2a2 Mon Sep 17 00:00:00 2001 From: Aaron Jorbin Date: Fri, 2 Sep 2016 04:16:00 +0000 Subject: [PATCH] Formatting: Allow KSES custom elements with hyphens The W3C Custom Elements spec (http://www.w3.org/TR/custom-elements/#concepts) allows you to use your own custom DOM elements/tags. One of the main requirements is that the tag name "must contain a U+002D HYPHEN-MINUS character". This adjusts KSES to allow it. Fixes #34105. Props batmoo. git-svn-id: https://develop.svn.wordpress.org/trunk@38511 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/kses.php | 2 +- tests/phpunit/tests/kses.php | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/kses.php b/src/wp-includes/kses.php index 8be3f79d56..fae60cdd95 100644 --- a/src/wp-includes/kses.php +++ b/src/wp-includes/kses.php @@ -781,7 +781,7 @@ function wp_kses_split2($string, $allowed_html, $allowed_protocols) { } // Allow HTML comments - if (!preg_match('%^<\s*(/\s*)?([a-zA-Z0-9]+)([^>]*)>?$%', $string, $matches)) + if (!preg_match('%^<\s*(/\s*)?([a-zA-Z0-9-]+)([^>]*)>?$%', $string, $matches)) return ''; // It's seriously malformed diff --git a/tests/phpunit/tests/kses.php b/tests/phpunit/tests/kses.php index e105813449..c9cf5d01db 100644 --- a/tests/phpunit/tests/kses.php +++ b/tests/phpunit/tests/kses.php @@ -360,6 +360,20 @@ EOF; $this->assertEquals( $allowedtags, wp_kses_allowed_html( 'data' ) ); } + function test_hyphenated_tag() { + $string = "Alot of hyphens."; + $custom_tags = array( + 'hyphenated-tag' => array( + 'attribute' => true, + ), + ); + $expect_stripped_string = 'Alot of hyphens.'; + + $expect_valid_string = "Alot of hyphens."; + $this->assertEquals( $expect_stripped_string, wp_kses_post( $string ) ); + $this->assertEquals( $expect_valid_string, wp_kses( $string, $custom_tags ) ); + } + /** * @ticket 26290 */