Ticket #29557: miqro-29557.2.patch
File miqro-29557.2.patch, 9.5 KB (added by , 10 years ago) |
---|
-
src/wp-includes/formatting.php
28 28 * @return string The string replaced with html entities 29 29 */ 30 30 function wptexturize($text, $reset = false) { 31 global $wp_cockneyreplace ;31 global $wp_cockneyreplace, $shortcode_tags; 32 32 static $static_characters, $static_replacements, $dynamic_characters, $dynamic_replacements, 33 33 $default_no_texturize_tags, $default_no_texturize_shortcodes, $run_texturize = true; 34 34 … … 205 205 206 206 // Look for shortcodes and HTML elements. 207 207 208 $tagnames = array_keys( $shortcode_tags ); 209 $tagregexp = join( '|', array_map( 'preg_quote', $tagnames ) ); 210 $tagregexp = "(?:$tagregexp)(?![\\w-])"; // Excerpt of get_shortcode_regex(). 211 208 212 $regex = '/(' // Capture the entire match. 209 213 . '<' // Find start of element. 210 214 . '(?(?=!--)' // Is this a comment? … … 215 219 . '|' 216 220 . '\[' // Find start of shortcode. 217 221 . '\[?' // Shortcodes may begin with [[ 222 . '/?' // Closing slash may precede name. 223 . $tagregexp // Only match registered shortcodes, because performance. 218 224 . '(?:' 219 225 . '[^\[\]<>]' // Shortcodes do not contain other shortcodes. 220 226 . '|' 221 227 . '<[^>]+>' // HTML elements permitted. Prevents matching ] before >. 222 . ') ++'228 . ')*+' 223 229 . '\]' // Find end of shortcode. 224 230 . '\]?' // Shortcodes may end with ]] 225 231 . ')/s'; … … 241 247 242 248 continue; 243 249 244 } elseif ( '[' === $first && 1 === preg_match( '/^\[ (?:[^\[\]<>]|<[^>]+>)++\]$/', $curl ) ) {245 // This is a shortcode delim iter.250 } elseif ( '[' === $first && 1 === preg_match( '/^\[\[?\/?' . $tagregexp . '(?:[^\[\]<>]|<[^>]+>)*+\]\]?$/', $curl ) ) { 251 // This is a shortcode delimeter. 246 252 247 _wptexturize_pushpop_element( $curl, $no_texturize_shortcodes_stack, $no_texturize_shortcodes ); 253 if ( '[[' !== substr( $curl, 0, 2 ) && ']]' !== substr( $curl, -2 ) ) { 254 // Looks like a normal shortcode. 255 _wptexturize_pushpop_element( $curl, $no_texturize_shortcodes_stack, $no_texturize_shortcodes ); 256 } else { 257 // Looks like an escaped shortcode. 258 // Do not texturize. 259 // Do not push to the shortcodes stack. 260 continue; 261 } 248 262 249 } elseif ( '[' === $first && 1 === preg_match( '/^\[\[?(?:[^\[\]<>]|<[^>]+>)++\]\]?$/', $curl ) ) {250 // This is an escaped shortcode delimiter.251 252 // Do not texturize.253 // Do not push to the shortcodes stack.254 255 continue;256 257 263 } elseif ( empty( $no_texturize_shortcodes_stack ) && empty( $no_texturize_tags_stack ) ) { 258 264 // This is neither a delimiter, nor is this content inside of no_texturize pairs. Do texturize. 259 265 … … 313 319 314 320 // Parse out the tag name. 315 321 $space = strpos( $text, ' ' ); 316 if ( FALSE=== $space ) {322 if ( false === $space ) { 317 323 $space = -1; 318 324 } else { 319 325 $space -= $name_offset; -
src/wp-includes/shortcodes.php
231 231 $tagregexp = join( '|', array_map('preg_quote', $tagnames) ); 232 232 233 233 // WARNING! Do not change this regex without changing do_shortcode_tag() and strip_shortcode_tag() 234 // Also, see shortcode_unautop() and shortcode.js .234 // Also, see shortcode_unautop() and shortcode.js and wptexturize(). 235 235 return 236 236 '\\[' // Opening bracket 237 237 . '(\\[?)' // 1: Optional second opening bracket for escaping shortcodes: [[tag]] -
tests/phpunit/tests/formatting/WPTexturize.php
11 11 12 12 function test_disable() { 13 13 $this->assertEquals('<pre>---</pre>', wptexturize('<pre>---</pre>')); 14 $this->assertEquals('[a]a–b[code]---[/code]a–b[/a]', wptexturize('[a]a--b[code]---[/code]a--b[/a]'));15 14 $this->assertEquals('<pre><code></code>--</pre>', wptexturize('<pre><code></code>--</pre>')); 16 15 17 16 $this->assertEquals( '<code>---</code>', wptexturize( '<code>---</code>' ) ); … … 1209 1208 '[gallery ...]]', 1210 1209 ), 1211 1210 array( 1212 '[/ ...]', // This would actually be ignored by the shortcode system. The decision to not texturize it is intentional, if not correct.1213 '[/ ...]',1211 '[/gallery ...]', // This would actually be ignored by the shortcode system. The decision to not texturize it is intentional, if not correct. 1212 '[/gallery ...]', 1214 1213 ), 1215 1214 array( 1216 1215 '[...]...[/...]', // These are potentially usable shortcodes. 1217 '[ ...]…[/...]',1216 '[…]…[/…]', 1218 1217 ), 1219 1218 array( 1220 '[[ ...]]...[[/...]]', // Shortcode parsing will ignore the inner ]...[ part and treat this as a single escaped shortcode.1221 '[[ ...]]…[[/...]]',1219 '[[gallery]]...[[/gallery]]', // Shortcode parsing will ignore the inner ]...[ part and treat this as a single escaped shortcode. 1220 '[[gallery]]…[[/gallery]]', 1222 1221 ), 1223 1222 array( 1224 '[[[ ...]]]...[[[/...]]]', // Again, shortcode parsing matches, but only the [[...] and [/...]] parts.1225 '[[[ ...]]]…[[[/...]]]',1223 '[[[gallery]]]...[[[/gallery]]]', // Again, shortcode parsing matches, but only the [[gallery] and [/gallery]] parts. 1224 '[[[gallery]]]…[[[/gallery]]]', 1226 1225 ), 1227 1226 array( 1228 '[[code]...[/code]...', // These are potentially usable shortcodes. Unfortunately, the meaning of [[code] is ambiguous unless we run the entire shortcode regexp.1229 '[[code]…[/code]…',1230 ),1231 array(1232 '[code]...[/code]]...', // These are potentially usable shortcodes. Unfortunately, the meaning of [/code]] is ambiguous unless we run the entire shortcode regexp.1233 '[code]...[/code]]...', // This test would not pass in 3.9 because the extra brace was always ignored by texturize.1234 ),1235 array(1236 1227 '[gal>ery ...]', 1237 1228 '[gal>ery …]', 1238 1229 ), … … 1345 1336 '[ but also catches the <b>styled “[quote]” here</b> ]', 1346 1337 ), 1347 1338 array( 1348 '[Let\'s get crazy<input>[ plugin code="<a href=\'?a[]=100\'>hello</a>"]</input>world]',1349 '[Let’s get crazy<input>[ plugin code="<a href=\'?a[]=100\'>hello</a>"]</input>world]',1339 '[Let\'s get crazy<input>[caption code="<a href=\'?a[]=100\'>hello</a>"]</input>world]', 1340 '[Let’s get crazy<input>[caption code="<a href=\'?a[]=100\'>hello</a>"]</input>world]', 1350 1341 ), 1351 1342 ); 1352 1343 } … … 1698 1689 '<code>hello</span>---</span>', 1699 1690 ), 1700 1691 array( 1701 '<span> hello[/code]---</span>',1702 '<span> hello[/code]—</span>',1692 '<span><code>hello</code>---</span>', 1693 '<span><code>hello</code>—</span>', 1703 1694 ), 1704 1695 array( 1705 ' [/code]hello<span>---</span>',1706 ' [/code]hello<span>—</span>',1696 '<code>hello</code>world<span>---</span>', 1697 '<code>hello</code>world<span>—</span>', 1707 1698 ), 1699 ); 1700 } 1701 1702 /** 1703 * Test disabling shortcode texturization. 1704 * 1705 * @ticket 29557 1706 * @dataProvider data_unregistered_shortcodes 1707 */ 1708 function test_unregistered_shortcodes( $input, $output ) { 1709 add_filter( 'no_texturize_shortcodes', array( $this, 'filter_shortcodes' ), 10, 1 ); 1710 1711 $output = $this->assertEquals( $output, wptexturize( $input ) ); 1712 1713 remove_filter( 'no_texturize_shortcodes', array( $this, 'filter_shortcodes' ), 10, 1 ); 1714 return $output; 1715 } 1716 1717 function filter_shortcodes( $disabled ) { 1718 $disabled[] = 'audio'; 1719 return $disabled; 1720 } 1721 1722 function data_unregistered_shortcodes() { 1723 return array( 1708 1724 array( 1709 '[ code]hello[/code]---</span>',1710 '[ code]hello[/code]—</span>',1725 '[a]a--b[audio]---[/audio]a--b[/a]', 1726 '[a]a–b[audio]---[/audio]a–b[/a]', 1711 1727 ), 1712 1728 array( 1713 ' <span>hello</span>---[code]',1714 ' <span>hello</span>—[code]',1729 '[code ...]...[/code]', // code is not a registered shortcode. 1730 '[code …]…[/code]', 1715 1731 ), 1716 1732 array( 1717 ' <span>hello[code]---</span>',1718 ' <span>hello[code]---</span>',1733 '[hello ...]...[/hello]', // hello is not a registered shortcode. 1734 '[hello …]…[/hello]', 1719 1735 ), 1720 1736 array( 1721 '[ code]hello<span>---</span>',1722 '[ code]hello<span>---</span>',1737 '[[audio]...[/audio]...', // These are potentially usable shortcodes. Unfortunately, the meaning of [[audio] is ambiguous unless we run the entire shortcode regexp. 1738 '[[audio]…[/audio]…', 1723 1739 ), 1724 1740 array( 1725 '[ code]hello</span>---</span>',1726 '[ code]hello</span>---</span>',1741 '[audio]...[/audio]]...', // These are potentially usable shortcodes. Unfortunately, the meaning of [/audio]] is ambiguous unless we run the entire shortcode regexp. 1742 '[audio]...[/audio]]...', // This test would not pass in 3.9 because the extra brace was always ignored by texturize. 1727 1743 ), 1744 array( 1745 '<span>hello[/audio]---</span>', 1746 '<span>hello[/audio]—</span>', 1747 ), 1748 array( 1749 '[/audio]hello<span>---</span>', 1750 '[/audio]hello<span>—</span>', 1751 ), 1752 array( 1753 '[audio]hello[/audio]---</span>', 1754 '[audio]hello[/audio]—</span>', 1755 ), 1756 array( 1757 '<span>hello</span>---[audio]', 1758 '<span>hello</span>—[audio]', 1759 ), 1760 array( 1761 '<span>hello[audio]---</span>', 1762 '<span>hello[audio]---</span>', 1763 ), 1764 array( 1765 '[audio]hello<span>---</span>', 1766 '[audio]hello<span>---</span>', 1767 ), 1768 array( 1769 '[audio]hello</span>---</span>', 1770 '[audio]hello</span>---</span>', 1771 ), 1728 1772 ); 1729 1773 } 1730 1774 } 1775 No newline at end of file