diff --git a/src/wp-includes/shortcodes.php b/src/wp-includes/shortcodes.php index c399bb0065..b466612887 100644 --- a/src/wp-includes/shortcodes.php +++ b/src/wp-includes/shortcodes.php @@ -309,7 +309,7 @@ function do_shortcode_tag( $m ) { */ function shortcode_parse_atts($text) { $atts = array(); - $pattern = '/(\w+)\s*=\s*"([^"]*)"(?:\s|$)|(\w+)\s*=\s*\'([^\']*)\'(?:\s|$)|(\w+)\s*=\s*([^\s\'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|(\S+)(?:\s|$)/'; + $pattern = '/([\w-]+)\s*=\s*"([^"]*)"(?:\s|$)|([\w-]+)\s*=\s*\'([^\']*)\'(?:\s|$)|([\w-]+)\s*=\s*([^\s\'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|(\S+)(?:\s|$)/'; $text = preg_replace("/[\x{00a0}\x{200b}]+/u", " ", $text); if ( preg_match_all($pattern, $text, $match, PREG_SET_ORDER) ) { foreach ($match as $m) { diff --git a/tests/phpunit/tests/shortcode.php b/tests/phpunit/tests/shortcode.php index daa3a58ac1..dd7ee23e16 100644 --- a/tests/phpunit/tests/shortcode.php +++ b/tests/phpunit/tests/shortcode.php @@ -119,6 +119,24 @@ class Tests_Shortcode extends WP_UnitTestCase { $this->assertEquals( '[hyphen-foo-bar-baz]', do_shortcode( '[hyphen-foo-bar-baz]' ) ); } + /** + * @ticket 9405 + */ + function test_attr_hyphen() { + do_shortcode('[test-shortcode-tag foo="foo" foo-bar="foo-bar" foo-bar-="foo-bar-" -foo-bar="-foo-bar" -foo-bar-="-foo-bar-" foo-bar-baz="foo-bar-baz" -foo-bar-baz="-foo-bar-baz" foo--bar="foo--bar" /]'); + $expected_attrs = array( + 'foo' => 'foo', + 'foo-bar' => 'foo-bar', + 'foo-bar-' => 'foo-bar-', + '-foo-bar' => '-foo-bar', + '-foo-bar-' => '-foo-bar-', + 'foo-bar-baz' => 'foo-bar-baz', + '-foo-bar-baz' => '-foo-bar-baz', + 'foo--bar' => 'foo--bar', + ); + $this->assertEquals( $expected_attrs, $this->atts ); + } + function test_two_atts() { do_shortcode('[test-shortcode-tag foo="asdf" bar="bing" /]'); $this->assertEquals( array('foo' => 'asdf', 'bar' => 'bing'), $this->atts );