WordPress.org

Make WordPress Core

Changeset 30456


Ignore:
Timestamp:
11/20/2014 02:39:12 PM (7 years ago)
Author:
nacin
Message:

Anchor texturize to shortcodes to improve regex efficiency.

Merges [30452] to the 3.7 branch.

props miqrogroove.
see #29557 for segfault issues.

Location:
branches/3.7
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/3.7

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

    r25695 r30456  
    108108    $no_texturize_shortcodes_stack = array();
    109109
    110     $textarr = preg_split('/(<.*>|\[.*\])/Us', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
     110    // Look for shortcodes and HTML elements.
     111   
     112    $shortcode_regex =
     113          '\['          // Find start of shortcode.
     114        . '[^\[\]<>]++' // Shortcodes do not contain other shortcodes. Possessive critical.
     115        . '\]';         // Find end of shortcode.
     116
     117    $textarr = preg_split("/(<[^>]*>|$shortcode_regex)/s", $text, -1, PREG_SPLIT_DELIM_CAPTURE);
    111118
    112119    foreach ( $textarr as &$curl ) {
     
    118125        if ( '<' === $first ) {
    119126            _wptexturize_pushpop_element($curl, $no_texturize_tags_stack, $no_texturize_tags, '<', '>');
    120         } elseif ( '[' === $first ) {
     127        } elseif ( '[' === $first && 1 === preg_match( '/^' . $shortcode_regex . '$/', $curl ) ) {
    121128            _wptexturize_pushpop_element($curl, $no_texturize_shortcodes_stack, $no_texturize_shortcodes, '[', ']');
    122129        } elseif ( empty($no_texturize_shortcodes_stack) && empty($no_texturize_tags_stack) ) {
     
    159166            array_push($stack, $matches[1]);
    160167        }
     168    } elseif ( 0 == count( $stack ) ) {
     169        // Stack is empty. Just stop.
    161170    } else {
    162171        // Closing? Check $text+2 against disabled elements
Note: See TracChangeset for help on using the changeset viewer.