Changeset 29748
- Timestamp:
- 09/17/2014 03:13:24 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/formatting.php
r29715 r29748 29 29 */ 30 30 function wptexturize($text, $reset = false) { 31 global $wp_cockneyreplace ;31 global $wp_cockneyreplace; 32 32 static $static_characters, $static_replacements, $dynamic_characters, $dynamic_replacements, 33 33 $default_no_texturize_tags, $default_no_texturize_shortcodes, $run_texturize = true; … … 206 206 // Look for shortcodes and HTML elements. 207 207 208 209 210 211 208 212 $regex = '/(' // Capture the entire match. 209 213 . '<' // Find start of element. … … 216 220 . '\[' // Find start of shortcode. 217 221 . '\[?' // Shortcodes may begin with [[ 218 . '(?:' 219 . '[^\[\]<>]' // Shortcodes do not contain other shortcodes. 220 . '|' 221 . '<[^>]+>' // HTML elements permitted. Prevents matching ] before >. 222 . ')++' 222 . '\/?' // Closing slash may precede name. 223 . $tagregexp // Only match registered shortcodes, because performance. 224 . '[^\[\]]*' // Shortcodes do not contain other shortcodes. 223 225 . '\]' // Find end of shortcode. 224 226 . '\]?' // Shortcodes may end with ]] … … 242 244 continue; 243 245 244 } elseif ( '[' === $first && 1 === preg_match( '/^\[ (?:[^\[\]<>]|<[^>]+>)++\]$/', $curl ) ) {246 } elseif ( '[' === $first && 1 === preg_match( '/^\[$/', $curl ) ) { 245 247 // This is a shortcode delimiter. 246 248 247 _wptexturize_pushpop_element( $curl, $no_texturize_shortcodes_stack, $no_texturize_shortcodes );248 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;249 250 // Looks like a normal shortcode. 251 252 253 // Looks like an escaped shortcode. 254 // Do not texturize. 255 // Do not push to the shortcodes stack. 256 continue; 257 256 258 257 259 } elseif ( empty( $no_texturize_shortcodes_stack ) && empty( $no_texturize_tags_stack ) ) { … … 314 316 // Parse out the tag name. 315 317 $space = strpos( $text, ' ' ); 316 if ( FALSE=== $space ) {318 if ( === $space ) { 317 319 $space = -1; 318 320 } else { -
trunk/src/wp-includes/shortcodes.php
r29207 r29748 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. 235 235 return 236 236 '\\[' // Opening bracket -
trunk/tests/phpunit/tests/formatting/WPTexturize.php
r28971 r29748 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 … … 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 '[/...]', // This would actually be ignored by the shortcode system. The decision to not texturize it is intentional, if not correct. 1212 '[/...]', 1214 1213 ), 1215 1214 array( 1216 1215 '[...]...[/...]', // These are potentially usable shortcodes. 1217 '[...]…[/...]', 1218 ), 1219 array( 1220 '[[...]]...[[/...]]', // Shortcode parsing will ignore the inner ]...[ part and treat this as a single escaped shortcode. 1221 '[[...]]…[[/...]]', 1222 ), 1223 array( 1224 '[[[...]]]...[[[/...]]]', // Again, shortcode parsing matches, but only the [[...] and [/...]] parts. 1225 '[[[...]]]…[[[/...]]]', 1226 ), 1227 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. 1216 '[…]…[/…]', 1217 ), 1218 array( 1219 '[[gallery]]...[[/gallery]]', // Shortcode parsing will ignore the inner ]...[ part and treat this as a single escaped shortcode. 1220 '[[gallery]]…[[/gallery]]', 1221 ), 1222 array( 1223 '[[[gallery]]]...[[[/gallery]]]', // Again, shortcode parsing matches, but only the [[gallery] and [/gallery]] parts. 1224 '[[[gallery]]]…[[[/gallery]]]', 1234 1225 ), 1235 1226 array( … … 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>[ 1340 '[Let’s get crazy<input>[]</input>world]', 1350 1341 ), 1351 1342 ); … … 1699 1690 ), 1700 1691 array( 1701 '<span>hello[/code]---</span>', 1702 '<span>hello[/code]—</span>', 1703 ), 1704 array( 1705 '[/code]hello<span>---</span>', 1706 '[/code]hello<span>—</span>', 1707 ), 1708 array( 1709 '[code]hello[/code]---</span>', 1710 '[code]hello[/code]—</span>', 1711 ), 1712 array( 1713 '<span>hello</span>---[code]', 1714 '<span>hello</span>—[code]', 1715 ), 1716 array( 1717 '<span>hello[code]---</span>', 1718 '<span>hello[code]---</span>', 1719 ), 1720 array( 1721 '[code]hello<span>---</span>', 1722 '[code]hello<span>---</span>', 1723 ), 1724 array( 1725 '[code]hello</span>---</span>', 1726 '[code]hello</span>---</span>', 1692 '<span><code>hello</code>---</span>', 1693 '<span><code>hello</code>—</span>', 1694 ), 1695 array( 1696 '<code>hello</code>world<span>---</span>', 1697 '<code>hello</code>world<span>—</span>', 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( 1724 array( 1725 '[a]a--b[audio]---[/audio]a--b[/a]', 1726 '[a]a–b[audio]---[/audio]a–b[/a]', 1727 ), 1728 array( 1729 '[code ...]...[/code]', // code is not a registered shortcode. 1730 '[code …]…[/code]', 1731 ), 1732 array( 1733 '[hello ...]...[/hello]', // hello is not a registered shortcode. 1734 '[hello …]…[/hello]', 1735 ), 1736 array( 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]…', 1739 ), 1740 array( 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. 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>', 1727 1771 ), 1728 1772 );
Note: See TracChangeset
for help on using the changeset viewer.