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.


git-svn-id: https://develop.svn.wordpress.org/trunk@28761 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor 2014-06-17 17:40:07 +00:00
parent abddfc4b99
commit 03a6e5f1fb
2 changed files with 94 additions and 6 deletions

View File

@ -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;

View File

@ -1279,4 +1279,87 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase {
),
);
}
}
/**
* Year abbreviations consist of exactly two digits.
*
* @ticket 26850
* @dataProvider data_quotes_and_dashes
*/
function test_year_abbr( $input, $output ) {
return $this->assertEquals( $output, wptexturize( $input ) );
}
function data_year_abbr() {
return array(
array(
"word '99 word",
"word &#8217;99 word",
),
array(
"word '99. word",
"word &#8217;99. word",
),
array(
"word '99, word",
"word &#8217;99, word",
),
array(
"word '99; word",
"word &#8217;99; word",
),
array(
"word '99' word", // For this pattern, prime doesn't make sense. Should get apos and a closing quote.
"word &#8217;99&#8217; word",
),
array(
"word '99'. word",
"word &#8217;99&#8217;. word",
),
array(
"word '99', word",
"word &#8217;99&#8217;, word",
),
array(
"word '99.' word",
"word &#8217;99.&#8217; word",
),
array(
"word '99",
"word &#8217;99",
),
array(
"'99 word",
"&#8217;99 word",
),
array(
"word '999 word", // Does not match the apos pattern, should be opening quote.
"word &#8216;999 word",
),
array(
"word '9 word",
"word &#8216;9 word",
),
array(
"word '99.9 word",
"word &#8216;99.9 word",
),
array(
"word '999",
"word &#8216;999",
),
array(
"word '9",
"word &#8216;9",
),
array(
"in '4 years, 3 months,' Obama cut the deficit",
"in &#8216;4 years, 3 months,&#8217; Obama cut the deficit",
),
array(
"testing's '4' through 'quotes'",
"testing&#8217;s &#8216;4&#8217; through &#8216;quotes&#8217;",
),
);
}
}