WordPress.org

Make WordPress Core

Ticket #11257: ticket-11257.patch

File ticket-11257.patch, 2.3 KB (added by miqrogroove, 8 years ago)

Resolves unreasonable recursion depth during wpautop. Explanation to follow.

  • wp-includes/formatting.php

     
    216216        if (strpos($pee, '<pre') !== false)
    217217                $pee = preg_replace_callback('!(<pre[^>]*>)(.*?)</pre>!is', 'clean_pre', $pee );
    218218        $pee = preg_replace( "|\n</p>$|", '</p>', $pee );
    219         $pee = preg_replace('/<p>\s*?(' . get_shortcode_regex() . ')\s*<\/p>/s', '$1', $pee); // don't auto-p wrap shortcodes that stand alone
     219        $pee = preg_replace('/<p>\s*?(' . get_shortcode_regex(1) . ')\s*<\/p>/s', '$1', $pee); // don't auto-p wrap shortcodes that stand alone
    220220
    221221        return $pee;
    222222}
  • wp-includes/shortcodes.php

     
    168168 * @since 2.5
    169169 * @uses $shortcode_tags
    170170 *
     171 * @param int Backreference nesting context for this regexp.
    171172 * @return string The shortcode search regular expression
    172173 */
    173 function get_shortcode_regex() {
     174function get_shortcode_regex($nesting = 0) {
    174175        global $shortcode_tags;
    175176        $tagnames = array_keys($shortcode_tags);
    176177        $tagregexp = join( '|', array_map('preg_quote', $tagnames) );
    177178
     179    $backref = 2 + (int) $nesting;
     180
    178181        // WARNING! Do not change this regex without changing do_shortcode_tag() and strip_shortcodes()
    179         return '(.?)\[('.$tagregexp.')\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?(.?)';
     182        return '(.?)\\[('.$tagregexp.')\\b(.*?)\\/?\\](?:(.+?)\\[\\/\\'.$backref.'\\])?(.?)';
    180183}
    181184
    182185/**
     
    194197        global $shortcode_tags;
    195198
    196199        // allow [[foo]] syntax for escaping a tag
    197         if ($m[1] == '[' && $m[6] == ']') {
     200        if ($m[1] == '[' && $m[5] == ']') {
    198201                return substr($m[0], 1, -1);
    199202        }
    200203
    201204        $tag = $m[2];
    202205        $attr = shortcode_parse_atts($m[3]);
    203206
    204         if ( isset($m[5]) ) {
     207        if ( isset($m[4]) ) {
    205208                // enclosing tag - extra parameter
    206                 return $m[1] . call_user_func($shortcode_tags[$tag], $attr, $m[5], $m[2]) . $m[6];
     209                return $m[1] . call_user_func($shortcode_tags[$tag], $attr, $m[4], $m[2]) . $m[5];
    207210        } else {
    208211                // self-closing tag
    209                 return $m[1] . call_user_func($shortcode_tags[$tag], $attr, NULL, $m[2]) . $m[6];
     212                return $m[1] . call_user_func($shortcode_tags[$tag], $attr, NULL, $m[2]) . $m[5];
    210213        }
    211214}
    212215