From 96484fd3f918650227d0ededfbaed1c6528ad299 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Wed, 25 Jun 2014 17:48:20 +0000 Subject: [PATCH] Optimize the `wptexturize()` loop: * Take the ampersand pattern out of the loop for speed. * Fix old bugs in the ampersand pattern. * Refactor `_wptexturize_pushpop_element()` without PCRE for speed. * Update unit tests. Props miqrogroove. Fixes #28623. git-svn-id: https://develop.svn.wordpress.org/trunk@28831 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/formatting.php | 86 +++++++++++-------- .../phpunit/tests/formatting/WPTexturize.php | 26 +++++- 2 files changed, 72 insertions(+), 40 deletions(-) diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php index a073a7cde9..5af533932f 100644 --- a/src/wp-includes/formatting.php +++ b/src/wp-includes/formatting.php @@ -178,7 +178,7 @@ function wptexturize($text, $reset = false) { * * @param array $default_no_texturize_tags An array of HTML element names. */ - $no_texturize_tags = '(' . implode( '|', apply_filters( 'no_texturize_tags', $default_no_texturize_tags ) ) . ')'; + $no_texturize_tags = apply_filters( 'no_texturize_tags', $default_no_texturize_tags ); /** * Filter the list of shortcodes not to texturize. * @@ -186,7 +186,7 @@ function wptexturize($text, $reset = false) { * * @param array $default_no_texturize_shortcodes An array of shortcode names. */ - $no_texturize_shortcodes = '(' . implode( '|', apply_filters( 'no_texturize_shortcodes', $default_no_texturize_shortcodes ) ) . ')'; + $no_texturize_shortcodes = apply_filters( 'no_texturize_shortcodes', $default_no_texturize_shortcodes ); $no_texturize_tags_stack = array(); $no_texturize_shortcodes_stack = array(); @@ -206,7 +206,7 @@ function wptexturize($text, $reset = false) { . '(?:' . '[^\[\]<>]' // Shortcodes do not contain other shortcodes. . '|' - . '<.+?>' // HTML elements permitted. Prevents matching ] before >. + . '<.+?>' // HTML elements permitted. Prevents matching ] before >. . ')+' . '\]' // Find end of shortcode. . '\]?' // Shortcodes may end with ]] @@ -221,13 +221,13 @@ function wptexturize($text, $reset = false) { // This is an HTML delimeter. if ( '', '', ), + array( + 'word word', // Ensure we are not corrupting image URLs. + 'word word', + ), ); }