From f7ac0eed90e0aa8452b9cd49a995b31d83e7b3b9 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Tue, 17 Jun 2014 17:57:14 +0000 Subject: [PATCH] Add Unit Tests for i18n and `wptexturize()`. Don't confuse closing single quotes and apostrophes. See #27426. Built from https://develop.svn.wordpress.org/trunk@28762 git-svn-id: http://core.svn.wordpress.org/trunk@28575 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/formatting.php | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php index 55a0884619..ab3be7a76c 100644 --- a/wp-includes/formatting.php +++ b/wp-includes/formatting.php @@ -24,19 +24,21 @@ * @uses $wp_cockneyreplace Array of formatted entities for certain common phrases * * @param string $text The text to be formatted + * @param bool $reset Set to true for unit testing. Translated patterns will reset. * @return string The string replaced with html entities */ -function wptexturize($text) { +function wptexturize($text, $reset = false) { global $wp_cockneyreplace; static $static_characters, $static_replacements, $dynamic_characters, $dynamic_replacements, $default_no_texturize_tags, $default_no_texturize_shortcodes, $run_texturize = true; - if ( false === $run_texturize ) { + // If there's nothing to do, just stop. + if ( empty( $text ) || false === $run_texturize ) { return $text; } - // No need to set up these static variables more than once - if ( ! isset( $static_characters ) ) { + // Set up static variables. Run once only. + if ( $reset || ! isset( $static_characters ) ) { /** * Filter whether to skip running `wptexturize()`. * @@ -123,9 +125,9 @@ function wptexturize($text) { $dynamic[ '/(?<=\A|[([{<"\-]|' . $spaces . ')\'/' ] = $opening_single_quote; } - // Apostrophe in a word. No spaces or double apostrophes. + // Apostrophe in a word. No spaces, double apostrophes, or other punctuation. if ( "'" != $apos ) { - $dynamic[ '/(?[\]\-]|' . $spaces . ')/' ] = $apos; } // 9" (double prime) @@ -148,9 +150,9 @@ function wptexturize($text) { $dynamic[ '/"/' ] = $closing_quote; } - // Single quotes followed by spaces or a period. - if ( "'" !== $closing_single_quote ) { - $dynamic[ '/\'(?=\Z|\.|' . $spaces . ')/' ] = $closing_single_quote; + // Single quotes followed by spaces or ending punctuation. + if ( "'" != $closing_single_quote ) { + $dynamic[ '/\'(?=\Z|[.,)}>\-\]]|' . $spaces . ')/' ] = $closing_single_quote; } // Dashes and spaces @@ -163,11 +165,6 @@ function wptexturize($text) { $dynamic_replacements = array_values( $dynamic ); } - // If there's nothing to do, just stop. - if ( empty( $text ) ) { - return $text; - } - // Transform into regexp sub-expression used in _wptexturize_pushpop_element // Must do this every time in case plugins use these filters in a context sensitive manner /**