Make WordPress Core

Changeset 30455 for branches/3.8


Ignore:
Timestamp:
11/20/2014 02:36:42 PM (10 years ago)
Author:
nacin
Message:

Anchor texturize to shortcodes to improve regex efficiency.

Merges [30452] to the 3.8 branch.

props miqrogroove.
see #29557 for segfault issues.

Location:
branches/3.8
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/3.8

  • branches/3.8/src/wp-includes/formatting.php

    r26851 r30455  
    122122    $no_texturize_shortcodes_stack = array();
    123123
    124     $textarr = preg_split('/(<.*>|\[.*\])/Us', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
     124    // Look for shortcodes and HTML elements.
     125   
     126    $shortcode_regex =
     127          '\['          // Find start of shortcode.
     128        . '[^\[\]<>]++' // Shortcodes do not contain other shortcodes. Possessive critical.
     129        . '\]';         // Find end of shortcode.
     130
     131    $textarr = preg_split("/(<[^>]*>|$shortcode_regex)/s", $text, -1, PREG_SPLIT_DELIM_CAPTURE);
    125132
    126133    foreach ( $textarr as &$curl ) {
     
    132139        if ( '<' === $first ) {
    133140            _wptexturize_pushpop_element($curl, $no_texturize_tags_stack, $no_texturize_tags, '<', '>');
    134         } elseif ( '[' === $first ) {
     141        } elseif ( '[' === $first && 1 === preg_match( '/^' . $shortcode_regex . '$/', $curl ) ) {
    135142            _wptexturize_pushpop_element($curl, $no_texturize_shortcodes_stack, $no_texturize_shortcodes, '[', ']');
    136143        } elseif ( empty($no_texturize_shortcodes_stack) && empty($no_texturize_tags_stack) ) {
     
    173180            array_push($stack, $matches[1]);
    174181        }
     182    } elseif ( 0 == count( $stack ) ) {
     183        // Stack is empty. Just stop.
    175184    } else {
    176185        // Closing? Check $text+2 against disabled elements
Note: See TracChangeset for help on using the changeset viewer.