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
This commit is contained in:
Aaron Jorbin 2016-09-02 04:16:00 +00:00
parent cce5a95dfa
commit 4484e2d2c3
2 changed files with 15 additions and 1 deletions

View File

@ -781,7 +781,7 @@ function wp_kses_split2($string, $allowed_html, $allowed_protocols) {
} }
// Allow HTML comments // 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 ''; return '';
// It's seriously malformed // It's seriously malformed

View File

@ -360,6 +360,20 @@ EOF;
$this->assertEquals( $allowedtags, wp_kses_allowed_html( 'data' ) ); $this->assertEquals( $allowedtags, wp_kses_allowed_html( 'data' ) );
} }
function test_hyphenated_tag() {
$string = "<hyphenated-tag attribute=\"value\" otherattribute=\"value2\">Alot of hyphens.</hyphenated-tag>";
$custom_tags = array(
'hyphenated-tag' => array(
'attribute' => true,
),
);
$expect_stripped_string = 'Alot of hyphens.';
$expect_valid_string = "<hyphenated-tag attribute=\"value\">Alot of hyphens.</hyphenated-tag>";
$this->assertEquals( $expect_stripped_string, wp_kses_post( $string ) );
$this->assertEquals( $expect_valid_string, wp_kses( $string, $custom_tags ) );
}
/** /**
* @ticket 26290 * @ticket 26290
*/ */