Ticket #35022: 35022.3.patch
File 35022.3.patch, 3.6 KB (added by , 9 years ago) |
---|
-
src/wp-includes/formatting.php
216 216 217 217 // Look for shortcodes and HTML elements. 218 218 219 preg_match_all( '@\[/?( [^<>&/\[\]\x00-\x20=]++)@', $text, $matches );219 preg_match_all( '@\[/?(' . WP_SHORTCODE_NAME_NON_TERMINATORS . '++)@', $text, $matches ); 220 220 $tagnames = array_intersect( array_keys( $shortcode_tags ), $matches[1] ); 221 221 $found_shortcodes = ! empty( $tagnames ); 222 222 $shortcode_regex = $found_shortcodes ? _get_wptexturize_shortcode_regex( $tagnames ) : ''; -
src/wp-includes/shortcodes.php
41 41 */ 42 42 $shortcode_tags = array(); 43 43 44 if ( in_array( get_option( 'blog_charset' ), array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ) ) ) { 45 define( 'WP_SHORTCODE_NAME_TERMINATORS', '(?:[<>&\/\[\]\x00-\x20=]|\xC2\xA0)' ); 46 define( 'WP_SHORTCODE_NAME_NON_TERMINATORS', '(?:[^<>&\/\[\]\x00-\x20=\xC2]|\xC2[^\xA0])' ); 47 } else { 48 define( 'WP_SHORTCODE_NAME_TERMINATORS', '[<>&\/\[\]\x00-\x20=]' ); 49 define( 'WP_SHORTCODE_NAME_NON_TERMINATORS', '[^<>&\/\[\]\x00-\x20=]' ); 50 } 51 44 52 /** 45 53 * Add hook for shortcode tag. 46 54 * … … 95 103 return; 96 104 } 97 105 98 if ( 0 !== preg_match( '@ [<>&/\[\]\x00-\x20=]@', $tag ) ) {106 if ( 0 !== preg_match( '@' . WP_SHORTCODE_NAME_TERMINATORS . '@', $tag ) ) { 99 107 /* translators: 1: shortcode name, 2: space separated list of reserved characters */ 100 108 $message = sprintf( __( 'Invalid shortcode name: %1$s. Do not use spaces or reserved characters: %2$s' ), $tag, '& / < > [ ] =' ); 101 109 _doing_it_wrong( __FUNCTION__, $message, '4.4.0' ); … … 210 218 return $content; 211 219 212 220 // Find all registered tag names in $content. 213 preg_match_all( '@\[( [^<>&/\[\]\x00-\x20=]++)@', $content, $matches );221 preg_match_all( '@\[(' . WP_SHORTCODE_NAME_NON_TERMINATORS . '++)@', $content, $matches ); 214 222 $tagnames = array_intersect( array_keys( $shortcode_tags ), $matches[1] ); 215 223 216 224 if ( empty( $tagnames ) ) { … … 481 489 function shortcode_parse_atts($text) { 482 490 $atts = array(); 483 491 $pattern = get_shortcode_atts_regex(); 492 484 493 $text = preg_replace("/[\x{00a0}\x{200b}]+/u", " ", $text); 485 494 if ( preg_match_all($pattern, $text, $match, PREG_SET_ORDER) ) { 486 495 foreach ($match as $m) { … … 578 587 return $content; 579 588 580 589 // Find all registered tag names in $content. 581 preg_match_all( '@\[( [^<>&/\[\]\x00-\x20=]++)@', $content, $matches );590 preg_match_all( '@\[(' . WP_SHORTCODE_NAME_NON_TERMINATORS . '++)@', $content, $matches ); 582 591 $tagnames = array_intersect( array_keys( $shortcode_tags ), $matches[1] ); 583 592 584 593 if ( empty( $tagnames ) ) { -
tests/phpunit/tests/shortcode.php
312 312 } 313 313 314 314 /** 315 * @ticket 35022 316 */ 317 public function test_non_breaking_space_following_shortcode_tag() { 318 do_shortcode( "[test-shortcode-tag\xC2\xA0foo=\"bar\"]" ); 319 $this->assertSame( 'test-shortcode-tag', $this->tagname ); 320 $this->assertSame( array( 'foo' => 'bar' ), $this->atts ); 321 } 322 323 /** 324 * @ticket 35022 325 */ 326 public function test_non_non_breaking_space_following_shortcode_tag() { 327 do_shortcode( "[test-shortcode-tag\xC2\xA1foo=\"bar\"]" ); 328 $this->assertNull( $this->tagname ); 329 $this->assertNull( $this->atts ); 330 } 331 332 /** 315 333 * @ticket 6562 316 334 */ 317 335 function test_utf8_whitespace_2() {