Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 30 additions & 78 deletions src/wp-includes/kses.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,10 @@
'target' => true,
),
'article' => array(
'align' => true,
'dir' => true,
'lang' => true,
'xml:lang' => true,
'align' => true,
),
'aside' => array(
'align' => true,
'dir' => true,
'lang' => true,
'xml:lang' => true,
'align' => true,
),
'audio' => array(
'autoplay' => true,
Expand All @@ -101,14 +95,10 @@
'src' => true,
),
'b' => array(),
'bdo' => array(
'dir' => true,
),
'bdo' => array(),
'big' => array(),
'blockquote' => array(
'cite' => true,
'lang' => true,
'xml:lang' => true,
'cite' => true,
),
'br' => array(),
'button' => array(
Expand All @@ -120,17 +110,13 @@
'caption' => array(
'align' => true,
),
'cite' => array(
'dir' => true,
'lang' => true,
),
'cite' => array(),
'code' => array(),
'col' => array(
'align' => true,
'char' => true,
'charoff' => true,
'span' => true,
'dir' => true,
'valign' => true,
'width' => true,
),
Expand All @@ -148,44 +134,29 @@
'dd' => array(),
'dfn' => array(),
'details' => array(
'align' => true,
'dir' => true,
'lang' => true,
'open' => true,
'xml:lang' => true,
'align' => true,
'open' => true,
),
'div' => array(
'align' => true,
'dir' => true,
'lang' => true,
'xml:lang' => true,
'align' => true,
),
'dl' => array(),
'dt' => array(),
'em' => array(),
'fieldset' => array(),
'figure' => array(
'align' => true,
'dir' => true,
'lang' => true,
'xml:lang' => true,
'align' => true,
),
'figcaption' => array(
'align' => true,
'dir' => true,
'lang' => true,
'xml:lang' => true,
'align' => true,
),
'font' => array(
'color' => true,
'face' => true,
'size' => true,
),
'footer' => array(
'align' => true,
'dir' => true,
'lang' => true,
'xml:lang' => true,
'align' => true,
),
'h1' => array(
'align' => true,
Expand All @@ -206,16 +177,10 @@
'align' => true,
),
'header' => array(
'align' => true,
'dir' => true,
'lang' => true,
'xml:lang' => true,
'align' => true,
),
'hgroup' => array(
'align' => true,
'dir' => true,
'lang' => true,
'xml:lang' => true,
'align' => true,
),
'hr' => array(
'align' => true,
Expand Down Expand Up @@ -253,10 +218,7 @@
'value' => true,
),
'main' => array(
'align' => true,
'dir' => true,
'lang' => true,
'xml:lang' => true,
'align' => true,
),
'map' => array(
'name' => true,
Expand All @@ -266,10 +228,7 @@
'type' => true,
),
'nav' => array(
'align' => true,
'dir' => true,
'lang' => true,
'xml:lang' => true,
'align' => true,
),
'object' => array(
'data' => array(
Expand All @@ -282,10 +241,7 @@
),
),
'p' => array(
'align' => true,
'dir' => true,
'lang' => true,
'xml:lang' => true,
'align' => true,
),
'pre' => array(
'width' => true,
Expand All @@ -296,26 +252,17 @@
's' => array(),
'samp' => array(),
'span' => array(
'dir' => true,
'align' => true,
'lang' => true,
'xml:lang' => true,
'align' => true,
),
'section' => array(
'align' => true,
'dir' => true,
'lang' => true,
'xml:lang' => true,
'align' => true,
),
'small' => array(),
'strike' => array(),
'strong' => array(),
'sub' => array(),
'summary' => array(
'align' => true,
'dir' => true,
'lang' => true,
'xml:lang' => true,
'align' => true,
),
'sup' => array(),
'table' => array(
Expand All @@ -324,7 +271,6 @@
'border' => true,
'cellpadding' => true,
'cellspacing' => true,
'dir' => true,
'rules' => true,
'summary' => true,
'width' => true,
Expand All @@ -343,7 +289,6 @@
'char' => true,
'charoff' => true,
'colspan' => true,
'dir' => true,
'headers' => true,
'height' => true,
'nowrap' => true,
Expand Down Expand Up @@ -1237,7 +1182,7 @@ function( $required_attr_limits ) {
* Determines whether an attribute is allowed.
*
* @since 4.2.3
* @since 5.0.0 Add support for `data-*` wildcard attributes.
* @since 5.0.0 Added support for `data-*` wildcard attributes.
*
* @param string $name The attribute name. Passed by reference. Returns empty string when not allowed.
* @param string $value The attribute value. Passed by reference. Returns a filtered value.
Expand Down Expand Up @@ -1271,7 +1216,9 @@ function wp_kses_attr_check( &$name, &$value, &$whole, $vless, $element, $allowe
* Note: the attribute name should only contain `A-Za-z0-9_-` chars,
* double hyphens `--` are not accepted by WordPress.
*/
if ( strpos( $name_low, 'data-' ) === 0 && ! empty( $allowed_attr['data-*'] ) && preg_match( '/^data(?:-[a-z0-9_]+)+$/', $name_low, $match ) ) {
if ( strpos( $name_low, 'data-' ) === 0 && ! empty( $allowed_attr['data-*'] )
&& preg_match( '/^data(?:-[a-z0-9_]+)+$/', $name_low, $match )
) {
/*
* Add the whole attribute name to the allowed attributes and set any restrictions
* for the `data-*` attribute values for the current element.
Expand Down Expand Up @@ -2548,7 +2495,9 @@ function safecss_filter_attr( $css, $deprecated = '' ) {
* Helper function to add global attributes to a tag in the allowed HTML list.
*
* @since 3.5.0
* @since 5.0.0 Add support for `data-*` wildcard attributes.
* @since 5.0.0 Added support for `data-*` wildcard attributes.
* @since 6.0.0 Added `dir`, `lang`, and `xml:lang` to global attributes.
*
* @access private
* @ignore
*
Expand All @@ -2563,11 +2512,14 @@ function _wp_add_global_attributes( $value ) {
'aria-labelledby' => true,
'aria-hidden' => true,
'class' => true,
'data-*' => true,
'dir' => true,
'id' => true,
'lang' => true,
'style' => true,
'title' => true,
'role' => true,
'data-*' => true,
'xml:lang' => true,
);

if ( true === $value ) {
Expand Down
3 changes: 3 additions & 0 deletions tests/phpunit/tests/kses.php
Original file line number Diff line number Diff line change
Expand Up @@ -494,9 +494,12 @@ public function test_wp_kses_allowed_html() {

foreach ( $tags as $tag ) {
$this->assertTrue( $tag['class'] );
$this->assertTrue( $tag['dir'] );
$this->assertTrue( $tag['id'] );
$this->assertTrue( $tag['lang'] );
$this->assertTrue( $tag['style'] );
$this->assertTrue( $tag['title'] );
$this->assertTrue( $tag['xml:lang'] );
}

$this->assertSame( $allowedtags, wp_kses_allowed_html( 'data' ) );
Expand Down