Allow shortcode parameter names (attributes) to contain dashes.
Props aaroncampbell, tyxla, izem Fixes #9405 git-svn-id: https://develop.svn.wordpress.org/trunk@33118 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
41705c3e7c
commit
063637755b
@ -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) {
|
||||
|
@ -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 );
|
||||
|
Loading…
Reference in New Issue
Block a user