From 337e5f7ae4b2a7e38c87c6d6a836b6bf3654a215 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Tue, 17 Jun 2014 17:41:15 +0000 Subject: [PATCH] `wptexturize()` adjustments: * Only place an apostrophe before a number when it has exactly two digits. * Never match '99' with the single prime pattern. * Always assume '99' is an abbreviated year at the end of a quotation. * Add unit tests. * Resolves the unit test broken in [28721] for #8775. See #26850. Built from https://develop.svn.wordpress.org/trunk@28761 git-svn-id: http://core.svn.wordpress.org/trunk@28574 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/formatting.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php index 9551a61c65..55a0884619 100644 --- a/wp-includes/formatting.php +++ b/wp-includes/formatting.php @@ -100,6 +100,16 @@ function wptexturize($text) { // Pattern-based replacements of characters. $dynamic = array(); + // '99' is an ambiguous case among other patterns; assume it's an abbreviated year at the end of a quotation. + if ( "'" !== $apos && "'" !== $closing_single_quote ) { + $dynamic[ '/\'(\d\d)\'(?=\Z|[.,)}>\-\]]|' . $spaces . ')/' ] = $apos . '$1' . $closing_single_quote; + } + + // '99 '99s '99's (apostrophe) But never '9 or '999 or '99.0. + if ( "'" !== $apos ) { + $dynamic[ '/\'(?=\d\d(?:\Z|(?!\d|[.,]\d)))/' ] = $apos; + } + // Quoted Numbers like "42" or '42.00' if ( '"' !== $opening_quote && '"' !== $closing_quote ) { $dynamic[ '/(?<=\A|' . $spaces . ')"(\d[\d\.\,]*)"/' ] = $opening_quote . '$1' . $closing_quote; @@ -108,11 +118,6 @@ function wptexturize($text) { $dynamic[ '/(?<=\A|' . $spaces . ')\'(\d[\d\.\,]*)\'/' ] = $opening_single_quote . '$1' . $closing_single_quote; } - // '99 '99s '99's (apostrophe) - if ( "'" !== $apos ) { - $dynamic[ '/\'(?=\d)/' ] = $apos; - } - // Single quote at start, or preceded by (, {, <, [, ", -, or spaces. if ( "'" !== $opening_single_quote ) { $dynamic[ '/(?<=\A|[([{<"\-]|' . $spaces . ')\'/' ] = $opening_single_quote;