X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/9e77185fafaf4e60e2b73821e0e4b9b1a11fb85f..5d244c8fd9a27c9f89dd08da2af6fbc67d4fce63:/wp-includes/formatting.php?ds=sidebyside diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php index 1f18ab9d..7bd354af 100644 --- a/wp-includes/formatting.php +++ b/wp-includes/formatting.php @@ -11,13 +11,13 @@ * Replaces common plain text characters into formatted entities * * As an example, - * - * 'cause today's effort makes it worth tomorrow's "holiday"... - * + * + * 'cause today's effort makes it worth tomorrow's "holiday" ... + * * Becomes: - * - * ’cause today’s effort makes it worth tomorrow’s “holiday”… - * + * + * ’cause today’s effort makes it worth tomorrow’s “holiday” … + * * Code within certain html blocks are skipped. * * @since 0.71 @@ -28,7 +28,7 @@ * @return string The string replaced with html entities */ function wptexturize($text, $reset = false) { - global $wp_cockneyreplace; + global $wp_cockneyreplace, $shortcode_tags; static $static_characters, $static_replacements, $dynamic_characters, $dynamic_replacements, $default_no_texturize_tags, $default_no_texturize_shortcodes, $run_texturize = true; @@ -205,23 +205,40 @@ function wptexturize($text, $reset = false) { // Look for shortcodes and HTML elements. - $regex = '/(' // Capture the entire match. - . '<' // Find start of element. - . '(?(?=!--)' // Is this a comment? - . '.+?--\s*>' // Find end of comment - . '|' - . '[^>]+>' // Find end of element - . ')' + $tagnames = array_keys( $shortcode_tags ); + $tagregexp = join( '|', array_map( 'preg_quote', $tagnames ) ); + $tagregexp = "(?:$tagregexp)(?![\\w-])"; // Excerpt of get_shortcode_regex(). + + $comment_regex = + '!' // Start of comment, after the <. + . '(?:' // Unroll the loop: Consume everything until --> is found. + . '-(?!->)' // Dash not followed by end of comment. + . '[^\-]*+' // Consume non-dashes. + . ')*+' // Loop possessively. + . '(?:-->)?'; // End of comment. If not found, match all input. + + $shortcode_regex = + '\[' // Find start of shortcode. + . '[\/\[]?' // Shortcodes may begin with [/ or [[ + . $tagregexp // Only match registered shortcodes, because performance. + . '(?:' + . '[^\[\]<>]+' // Shortcodes do not contain other shortcodes. Quantifier critical. . '|' - . '\[' // Find start of shortcode. - . '\[?' // Shortcodes may begin with [[ - . '(?:' - . '[^\[\]<>]' // Shortcodes do not contain other shortcodes. - . '|' - . '<[^>]+>' // HTML elements permitted. Prevents matching ] before >. - . ')++' - . '\]' // Find end of shortcode. - . '\]?' // Shortcodes may end with ]] + . '<[^\[\]>]*>' // HTML elements permitted. Prevents matching ] before >. + . ')*+' // Possessive critical. + . '\]' // Find end of shortcode. + . '\]?'; // Shortcodes may end with ]] + + $regex = + '/(' // Capture the entire match. + . '<' // Find start of element. + . '(?(?=!--)' // Is this a comment? + . $comment_regex // Find end of comment. + . '|' + . '[^>]+>' // Find end of element. + . ')' + . '|' + . $shortcode_regex // Find shortcodes. . ')/s'; $textarr = preg_split( $regex, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY ); @@ -229,30 +246,31 @@ function wptexturize($text, $reset = false) { foreach ( $textarr as &$curl ) { // Only call _wptexturize_pushpop_element if $curl is a delimiter. $first = $curl[0]; - if ( '<' === $first && '>' === substr( $curl, -1 ) ) { - // This is an HTML delimiter. + if ( '<' === $first && '