Changeset 28831
- Timestamp:
- 06/25/2014 05:48:20 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/formatting.php
r28817 r28831 179 179 * @param array $default_no_texturize_tags An array of HTML element names. 180 180 */ 181 $no_texturize_tags = '(' . implode( '|', apply_filters( 'no_texturize_tags', $default_no_texturize_tags ) ) . ')';181 $no_texturize_tags = apply_filters( 'no_texturize_tags', $default_no_texturize_tags ); 182 182 /** 183 183 * Filter the list of shortcodes not to texturize. … … 187 187 * @param array $default_no_texturize_shortcodes An array of shortcode names. 188 188 */ 189 $no_texturize_shortcodes = '(' . implode( '|', apply_filters( 'no_texturize_shortcodes', $default_no_texturize_shortcodes ) ) . ')';189 $no_texturize_shortcodes = apply_filters( 'no_texturize_shortcodes', $default_no_texturize_shortcodes ); 190 190 191 191 $no_texturize_tags_stack = array(); … … 207 207 . '[^\[\]<>]' // Shortcodes do not contain other shortcodes. 208 208 . '|' 209 . '<.+?>' // HTML elements permitted. Prevents matching ] before >.209 . '<.+?>' // HTML elements permitted. Prevents matching ] before >. 210 210 . ')+' 211 211 . '\]' // Find end of shortcode. … … 222 222 223 223 if ( '<!--' !== substr( $curl, 0, 4 ) ) { 224 _wptexturize_pushpop_element( $curl, $no_texturize_tags_stack, $no_texturize_tags , '<', '>');224 _wptexturize_pushpop_element( $curl, $no_texturize_tags_stack, $no_texturize_tags ); 225 225 } 226 226 … … 228 228 // This is a shortcode delimeter. 229 229 230 _wptexturize_pushpop_element( $curl, $no_texturize_shortcodes_stack, $no_texturize_shortcodes , '[', ']');230 _wptexturize_pushpop_element( $curl, $no_texturize_shortcodes_stack, $no_texturize_shortcodes ); 231 231 232 232 } elseif ( '[' === $first && 1 === preg_match( '/^\[\[?(?:[^\[\]<>]|<.+?>)+\]\]?$/', $curl ) ) { … … 236 236 // Do not push to the shortcodes stack. 237 237 238 } elseif ( empty( $no_texturize_shortcodes_stack) && empty($no_texturize_tags_stack) ) {238 } elseif ( empty( $no_texturize_shortcodes_stack ) && empty( $no_texturize_tags_stack ) ) { 239 239 // This is neither a delimeter, nor is this content inside of no_texturize pairs. Do texturize. 240 240 241 $curl = str_replace( $static_characters, $static_replacements, $curl);242 $curl = preg_replace( $dynamic_characters, $dynamic_replacements, $curl);241 $curl = str_replace( $static_characters, $static_replacements, $curl ); 242 $curl = preg_replace( $dynamic_characters, $dynamic_replacements, $curl ); 243 243 244 244 // 9x9 (times), but never 0x9999 … … 248 248 } 249 249 } 250 251 // Replace each & with & unless it already looks like an entity. 252 $curl = preg_replace('/&([^#])(?![a-zA-Z1-4]{1,8};)/', '&$1', $curl); 253 } 254 return implode( '', $textarr ); 250 } 251 $text = implode( '', $textarr ); 252 253 // Replace each & with & unless it already looks like an entity. 254 $text = preg_replace('/&(?!#(?:\d+|x[a-f0-9]+);|[a-z1-4]{1,8};)/i', '&', $text); 255 256 return $text; 255 257 } 256 258 257 259 /** 258 260 * Search for disabled element tags. Push element to stack on tag open and pop 259 * on tag close. Assumes first character of $text is tag opening. 261 * on tag close. 262 * 263 * Assumes first char of $text is tag opening and last char is tag closing. 264 * Assumes second char of $text is optionally '/' to indicate closing as in </html>. 260 265 * 261 266 * @since 2.9.0 262 267 * @access private 263 268 * 264 * @param string $text Text to check. First character is assumed to be $opening 265 * @param array $stack Array used as stack of opened tag elements 266 * @param string $disabled_elements Tags to match against formatted as regexp sub-expression 267 * @param string $opening Tag opening character, assumed to be 1 character long 268 * @param string $closing Tag closing character 269 */ 270 function _wptexturize_pushpop_element($text, &$stack, $disabled_elements, $opening = '<', $closing = '>') { 271 // Check if it is a closing tag -- otherwise assume opening tag 272 if (strncmp($opening . '/', $text, 2)) { 273 // Opening? Check $text+1 against disabled elements 274 if (preg_match('/^' . $disabled_elements . '\b/', substr($text, 1), $matches)) { 269 * @param string $text Text to check. Must be a tag like <html> or [shortcode]. 270 * @param array $stack List of open tag elements. 271 * @param array $disabled_elements The tag names to match against. Spaces are not allowed in tag names. 272 */ 273 function _wptexturize_pushpop_element($text, &$stack, $disabled_elements) { 274 // Is it an opening tag or closing tag? 275 if ( '/' !== $text[1] ) { 276 $opening_tag = true; 277 $name_offset = 1; 278 } elseif ( 0 == count( $stack ) ) { 279 // Stack is empty. Just stop. 280 return; 281 } else { 282 $opening_tag = false; 283 $name_offset = 2; 284 } 285 286 // Parse out the tag name. 287 $space = strpos( $text, ' ' ); 288 if ( FALSE === $space ) { 289 $space = -1; 290 } else { 291 $space -= $name_offset; 292 } 293 $tag = substr( $text, $name_offset, $space ); 294 295 // Handle disabled tags. 296 if ( in_array( $tag, $disabled_elements ) ) { 297 if ( $opening_tag ) { 275 298 /* 276 299 * This disables texturize until we find a closing tag of our type … … 281 304 */ 282 305 283 array_push($stack, $matches[1]); 284 } 285 } elseif ( 0 == count( $stack ) ) { 286 // Stack is empty. Just stop. 287 } else { 288 // Closing? Check $text+2 against disabled elements 289 $c = preg_quote($closing, '/'); 290 if (preg_match('/^' . $disabled_elements . $c . '/', substr($text, 2), $matches)) { 291 $last = array_pop($stack); 292 293 // Make sure it matches the opening tag 294 if ( $last != $matches[1] ) { 295 array_push( $stack, $last ); 296 } 306 array_push( $stack, $tag ); 307 } elseif ( end( $stack ) == $tag ) { 308 array_pop( $stack ); 297 309 } 298 310 } -
trunk/tests/phpunit/tests/formatting/WPTexturize.php
r28773 r28831 831 831 ), 832 832 array( 833 "word ઼ word", 834 "word ઼ word", 835 ), 836 array( 837 "word Δ word", 838 "word Δ word", 839 ), 840 array( 833 841 "word &# word", 834 "word &# word", // invalid output?842 "word &# word", 835 843 ), 836 844 array( … … 840 848 array( 841 849 "word && word", 842 "word & & word",850 "word && word", 843 851 ), 844 852 array( 845 853 "word &!amp; word", 846 "word &!amp; word", 854 "word &!amp; word", 855 ), 856 array( 857 "word &#", 858 "word &#", 859 ), 860 array( 861 "word &", 862 "word &", 847 863 ), 848 864 ); … … 1285 1301 '<ul><li>Hello.</li><!--<li>Goodbye.</li>--></ul>', 1286 1302 '<ul><li>Hello.</li><!--<li>Goodbye.</li>--></ul>', 1303 ), 1304 array( 1305 'word <img src="http://example.com/wp-content/uploads/2014/06/image-300x216.gif" /> word', // Ensure we are not corrupting image URLs. 1306 'word <img src="http://example.com/wp-content/uploads/2014/06/image-300x216.gif" /> word', 1287 1307 ), 1288 1308 );
Note: See TracChangeset
for help on using the changeset viewer.