diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php index 5efe0cdadb..ae240a6ef6 100644 --- a/wp-includes/formatting.php +++ b/wp-includes/formatting.php @@ -152,7 +152,14 @@ function wptexturize($text) { $no_texturize_tags_stack = array(); $no_texturize_shortcodes_stack = array(); - $textarr = preg_split('/(<.*>|\[.*\])/Us', $text, -1, PREG_SPLIT_DELIM_CAPTURE); + // Look for shortcodes and HTML elements. + + $shortcode_regex = + '\[' // Find start of shortcode. + . '[^\[\]<>]++' // Shortcodes do not contain other shortcodes. Possessive critical. + . '\]'; // Find end of shortcode. + + $textarr = preg_split("/(<[^>]*>|$shortcode_regex)/s", $text, -1, PREG_SPLIT_DELIM_CAPTURE); foreach ( $textarr as &$curl ) { if ( empty( $curl ) ) { @@ -163,7 +170,7 @@ function wptexturize($text) { $first = $curl[0]; if ( '<' === $first ) { _wptexturize_pushpop_element($curl, $no_texturize_tags_stack, $no_texturize_tags, '<', '>'); - } elseif ( '[' === $first ) { + } elseif ( '[' === $first && 1 === preg_match( '/^' . $shortcode_regex . '$/', $curl ) ) { _wptexturize_pushpop_element($curl, $no_texturize_shortcodes_stack, $no_texturize_shortcodes, '[', ']'); } elseif ( empty($no_texturize_shortcodes_stack) && empty($no_texturize_tags_stack) ) { @@ -214,6 +221,8 @@ function _wptexturize_pushpop_element($text, &$stack, $disabled_elements, $openi array_push($stack, $matches[1]); } + } elseif ( 0 == count( $stack ) ) { + // Stack is empty. Just stop. } else { // Closing? Check $text+2 against disabled elements $c = preg_quote($closing, '/');