Fix abbreviations mixed with quotes, example: '99% of people'.

Add/alter unit tests.

Props miqrogroove.
Fixes #26850.


git-svn-id: https://develop.svn.wordpress.org/trunk@28765 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor 2014-06-17 20:18:38 +00:00
parent 1f4d925102
commit b11edb94d9
2 changed files with 13 additions and 9 deletions

View File

@ -111,17 +111,17 @@ function wptexturize($text, $reset = false) {
$dynamic[ '/\'(\d\d)"(?=\Z|[.,)}>\-\]]|' . $spaces . ')/' ] = $apos . '$1' . $closing_quote;
}
// '99 '99s '99's (apostrophe) But never '9 or '999 or '99.0.
// '99 '99s '99's (apostrophe) But never '9 or '99% or '999 or '99.0.
if ( "'" !== $apos ) {
$dynamic[ '/\'(?=\d\d(?:\Z|(?!\d|[.,]\d)))/' ] = $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;
$dynamic[ '/(?<=\A|' . $spaces . ')"(\d[.,\d]*)"/' ] = $opening_quote . '$1' . $closing_quote;
}
if ( "'" !== $opening_single_quote && "'" !== $closing_single_quote ) {
$dynamic[ '/(?<=\A|' . $spaces . ')\'(\d[\d\.\,]*)\'/' ] = $opening_single_quote . '$1' . $closing_single_quote;
$dynamic[ '/(?<=\A|' . $spaces . ')\'(\d[.,\d]*)\'/' ] = $opening_single_quote . '$1' . $closing_single_quote;
}
// Single quote at start, or preceded by (, {, <, [, ", -, or spaces.

View File

@ -313,8 +313,8 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase {
"word &#8217;99&#8217;s word",
),
array(
"according to our source, '33% of all students scored less than 50' on the test.", // Apostrophes and primes have priority over quotes
"according to our source, &#8217;33% of all students scored less than 50&#8242; on the test.",
"according to our source, '33 students scored less than 50' on the test.", // Apostrophes and primes have priority over quotes
"according to our source, &#8217;33 students scored less than 50&#8242; on the test.",
),
);
}
@ -1060,12 +1060,12 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase {
'word &#8220;4,242.00&#8221; word',
),
array(
"word '99's word", // Is this correct?
"word &#8216;99&#8217;s word",
"word '99's word",
"word &#8217;99&#8217;s word",
),
array(
"word '99'samsonite",
"word &#8216;99&#8217;samsonite",
"word &#8217;99&#8217;samsonite",
),
);
}
@ -1340,6 +1340,10 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase {
"word '999 word", // Does not match the apos pattern, should be opening quote.
"word &#8216;999 word",
),
array(
"word '99% word",
"word &#8216;99% word",
),
array(
"word '9 word",
"word &#8216;9 word",