diff --git a/src/wp-includes/shortcodes.php b/src/wp-includes/shortcodes.php index bddf63ada28a3..e1d37215546cd 100644 --- a/src/wp-includes/shortcodes.php +++ b/src/wp-includes/shortcodes.php @@ -616,11 +616,11 @@ function shortcode_parse_atts( $text ) { $text = preg_replace( "/[\x{00a0}\x{200b}]+/u", ' ', $text ); if ( preg_match_all( $pattern, $text, $match, PREG_SET_ORDER ) ) { foreach ( $match as $m ) { - if ( ! empty( $m[1] ) ) { + if ( isset( $m[1] ) && '' !== $m[1] ) { $atts[ strtolower( $m[1] ) ] = stripcslashes( $m[2] ); - } elseif ( ! empty( $m[3] ) ) { + } elseif ( isset( $m[3] ) && '' !== $m[3] ) { $atts[ strtolower( $m[3] ) ] = stripcslashes( $m[4] ); - } elseif ( ! empty( $m[5] ) ) { + } elseif ( isset( $m[5] ) && '' !== $m[5] ) { $atts[ strtolower( $m[5] ) ] = stripcslashes( $m[6] ); } elseif ( isset( $m[7] ) && strlen( $m[7] ) ) { $atts[] = stripcslashes( $m[7] ); diff --git a/tests/phpunit/tests/shortcode.php b/tests/phpunit/tests/shortcode.php index 2c5b04d02e147..4f01b327f2710 100644 --- a/tests/phpunit/tests/shortcode.php +++ b/tests/phpunit/tests/shortcode.php @@ -1019,4 +1019,81 @@ public function test_shortcode_parse_atts_empty() { $this->assertIsArray( $out, 'Return value is not an array' ); $this->assertEmpty( $out, 'Returned array is not empty' ); } + + /** + * @dataProvider data_should_return_expected_attributes_when_shortcode_is_parsed + */ + public function test_should_return_expected_attributes_when_shortcode_is_parsed( $input, $expected ) { + $this->assertSame( $expected, shortcode_parse_atts( $input ) ); + } + + public function data_should_return_expected_attributes_when_shortcode_is_parsed() { + return array( + 'basic_attributes' => array( + 'attr1="value1" attr2="value2"', + array( + 'attr1' => 'value1', + 'attr2' => 'value2', + ), + ), + 'mixed_case_attributes' => array( + 'Attr1="value1" ATTR2="value2"', + array( + 'attr1' => 'value1', + 'attr2' => 'value2', + ), + ), + 'single_quotes' => array( + "attr1='value1' attr2='value2'", + array( + 'attr1' => 'value1', + 'attr2' => 'value2', + ), + ), + 'unclosed_html_elements' => array( + 'attr1="