Ticket #47863: 47863-2.diff
File 47863-2.diff, 4.1 KB (added by , 5 years ago) |
---|
-
src/wp-includes/shortcodes.php
diff --git src/wp-includes/shortcodes.php src/wp-includes/shortcodes.php index b32b023..5fa5416 100644
function get_shortcode_atts_regex() { 488 488 * retrieval of the attributes, since all attributes have to be known. 489 489 * 490 490 * @since 2.5.0 491 * @since 5.3.0 Support of a full shortcode input. 491 492 * 492 * @param string $text 493 * @param string $text Any single shortcode of any format or key/value pair string. 493 494 * @return array|string List of attribute values. 494 495 * Returns empty array if trim( $text ) == '""'. 495 496 * Returns empty string if trim( $text ) == ''. … … function get_shortcode_atts_regex() { 498 499 function shortcode_parse_atts( $text ) { 499 500 $atts = array(); 500 501 $pattern = get_shortcode_atts_regex(); 501 $text = preg_replace( "/[\x{00a0}\x{200b}]+/u", ' ', $text ); 502 $text = trim( preg_replace( "/[\x{00a0}\x{200b}]+/u", ' ', $text ) ); 503 504 // Remove everything but attributes from shortcode. 505 if ( preg_match( '/^\[[\w-]+([^\]]*)\]/', $text, $matches ) ) { 506 if ( count( $matches ) === 2 ) { 507 $text = trim( $matches[1], ' \/' ); 508 } 509 } 510 502 511 if ( preg_match_all( $pattern, $text, $match, PREG_SET_ORDER ) ) { 503 512 foreach ( $match as $m ) { 504 513 if ( ! empty( $m[1] ) ) { … … function shortcode_parse_atts( $text ) { 516 525 } 517 526 } 518 527 519 // Reject any unclosed HTML elements 528 // Reject any unclosed HTML elements. 520 529 foreach ( $atts as &$value ) { 521 530 if ( false !== strpos( $value, '<' ) ) { 522 531 if ( 1 !== preg_match( '/^[^<]*+(?:<[^>]*+>[^<]*+)*+$/', $value ) ) { … … function shortcode_parse_atts( $text ) { 527 536 } else { 528 537 $atts = ltrim( $text ); 529 538 } 539 530 540 return $atts; 531 541 } 532 542 -
tests/phpunit/tests/shortcode.php
diff --git tests/phpunit/tests/shortcode.php tests/phpunit/tests/shortcode.php index a978779..25aea90 100644
EOF; 972 972 ); 973 973 $this->assertEquals( 'test-shortcode-tag', $this->tagname ); 974 974 } 975 976 /** 977 * Testing the `shortcode_parse_atts()` function. 978 * 979 * @ticket 47863 980 * 981 * @covers ::shortcode_parse_atts 982 * @dataProvider data_shortcode_parse_atts 983 * 984 * @param string $text A single shortcode format or key/value pair string. 985 * @param string|array $expected Expected results. 986 */ 987 public function test_shortcode_parse_atts( $text, $expected ) { 988 $actual = shortcode_parse_atts( $text ); 989 $this->assertSame( $expected, $actual ); 990 } 991 992 /** 993 * Data provider for `test_shortcode_parse_atts()`. 994 * 995 * @return array { 996 * @type array { 997 * @type string $text A single shortcode format or key/value pair string. 998 * @type string|array $expected The expected result. 999 * } 1000 * } 1001 */ 1002 public function data_shortcode_parse_atts() { 1003 1004 return array( 1005 array( 1006 '', 1007 '', 1008 ), 1009 array( 1010 ' ', 1011 '', 1012 ), 1013 array( 1014 '""', 1015 array(), 1016 ), 1017 array( 1018 '\'\'', 1019 array(), 1020 ), 1021 array( 1022 '[unittest]', 1023 '', 1024 ), 1025 array( 1026 '[unitest]Unit Test[/unittest]', 1027 '', 1028 ), 1029 array( 1030 '[unittest title="unittest" link="https://unit.test/"]', 1031 array( 1032 'title' => 'unittest', 1033 'link' => 'https://unit.test/', 1034 ), 1035 ), 1036 array( 1037 '[unittest title="unittest" link="https://unit.test/"/]', 1038 array( 1039 'title' => 'unittest', 1040 'link' => 'https://unit.test/', 1041 ), 1042 ), 1043 array( 1044 '[unit_test title="unittest" link="https://unit.test/"/]', 1045 array( 1046 'title' => 'unittest', 1047 'link' => 'https://unit.test/', 1048 ), 1049 ), 1050 array( 1051 '[unit-test title="unittest" link="https://unit.test/"/]', 1052 array( 1053 'title' => 'unittest', 1054 'link' => 'https://unit.test/', 1055 ), 1056 ), 1057 array( 1058 '[unittest title="unittest" link="https://unit.test/"]Unit Test[/unittest]', 1059 array( 1060 'title' => 'unittest', 1061 'link' => 'https://unit.test/', 1062 ), 1063 ), 1064 array( 1065 'title="unittest" link="https://unit.test/"', 1066 array( 1067 'title' => 'unittest', 1068 'link' => 'https://unit.test/', 1069 ), 1070 ), 1071 ); 1072 1073 } 1074 975 1075 }