Skip to content

Commit 342cac1

Browse files
Formatting: Avoid a PHP 7.2 warning in wp_kses_attr() when one of $allowedtags elements is an uncountable value.
Props andrei0x309, soulseekah, SergeyBiryukov. Merges [42860] to the 4.9 branch. Fixes #43312. git-svn-id: https://develop.svn.wordpress.org/branches/4.9@42861 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 99b7b99 commit 342cac1

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

src/wp-includes/kses.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,8 @@ function wp_kses_attr($element, $attr, $allowed_html, $allowed_protocols) {
827827
$xhtml_slash = ' /';
828828

829829
// Are any attributes allowed at all for this element?
830-
if ( ! isset( $allowed_html[ strtolower( $element ) ] ) || true === $allowed_html[ strtolower( $element ) ] || count( $allowed_html[ strtolower( $element ) ] ) == 0 ) {
830+
$element_low = strtolower( $element );
831+
if ( empty( $allowed_html[ $element_low ] ) || true === $allowed_html[ $element_low ] ) {
831832
return "<$element$xhtml_slash>";
832833
}
833834

tests/phpunit/tests/kses.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,4 +708,14 @@ function test_wp_kses_attr_single_attribute_is_allowed() {
708708

709709
$this->assertEquals( "<{$element} title=\"foo\">", wp_kses_attr( $element, $attribute, array( 'foo' => array( 'title' => true ) ), array() ) );
710710
}
711+
712+
/**
713+
* @ticket 43312
714+
*/
715+
function test_wp_kses_attr_no_attributes_allowed_with_false() {
716+
$element = 'foo';
717+
$attribute = 'title="foo" class="bar"';
718+
719+
$this->assertEquals( "<{$element}>", wp_kses_attr( $element, $attribute, array( 'foo' => false ), array() ) );
720+
}
711721
}

0 commit comments

Comments
 (0)