Make WordPress Core


Ignore:
Timestamp:
10/02/2015 04:25:40 AM (11 years ago)
Author:
wonderboymusic
Message:

Shortcodes/Formatting: Add PCRE Performance Testing

  • Move pattern from wptexturize() into a separate function.
  • Move pattern from wp_html_split() into a separate function.
  • Beautify code for wp_html_split().
  • Remove unnecessary instances of /s modifier in patterns that don't use dots.
  • Add tests/phpunit/data/formatting/whole-posts.php for testing larger strings.
  • Add function benchmark_pcre_backtracking().
  • Add tests for wp_html_split().
  • Add tests for wptexturize().
  • Add tests for get_shortcode_regex().

Props miqrogroove.
Fixes #34121.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/shortcodes.php

    r34747 r34761  
    169169
    170170        if ( shortcode_exists( $tag ) ) {
    171                 preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER );
     171                preg_match_all( '/' . get_shortcode_regex() . '/', $content, $matches, PREG_SET_ORDER );
    172172                if ( empty( $matches ) )
    173173                        return false;
    … …  
    220220
    221221        $pattern = get_shortcode_regex( $tagnames );
    222         $content = preg_replace_callback( "/$pattern/s", 'do_shortcode_tag', $content );
     222        $content = preg_replace_callback( "/$pattern/", 'do_shortcode_tag', $content );
    223223
    224224        // Always restore square braces so we don't break things like <!--[if IE ]>
    … …  
    379379                        // Some plugins are doing things like [name] <[email]>.
    380380                        if ( 1 === preg_match( '%^<\s*\[\[?[^\[\]]+\]%', $element ) ) {
    381                                 $element = preg_replace_callback( "/$pattern/s", 'do_shortcode_tag', $element );
     381                                $element = preg_replace_callback( "/$pattern/", 'do_shortcode_tag', $element );
    382382                        }
    383383
    … …  
    408408                                // was written by an administrator, so we should avoid changing the output
    409409                                // and we do not need to run KSES here.
    410                                 $attr = preg_replace_callback( "/$pattern/s", 'do_shortcode_tag', $attr );
     410                                $attr = preg_replace_callback( "/$pattern/", 'do_shortcode_tag', $attr );
    411411                        } else {
    412412                                // $attr like 'name = "[shortcode]"' or "name = '[shortcode]'"
    413413                                // We do not know if $content was unfiltered. Assume KSES ran before shortcodes.
    414414                                $count = 0;
    415                                 $new_attr = preg_replace_callback( "/$pattern/s", 'do_shortcode_tag', $attr, -1, $count );
     415                                $new_attr = preg_replace_callback( "/$pattern/", 'do_shortcode_tag', $attr, -1, $count );
    416416                                if ( $count > 0 ) {
    417417                                        // Sanitize the shortcode output using KSES.
    … …  
    573573
    574574        $pattern = get_shortcode_regex( $tagnames );
    575         $content = preg_replace_callback( "/$pattern/s", 'strip_shortcode_tag', $content );
     575        $content = preg_replace_callback( "/$pattern/", 'strip_shortcode_tag', $content );
    576576
    577577        // Always restore square braces so we don't break things like <!--[if IE ]>
Note: See TracChangeset for help on using the changeset viewer.