diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php index cfc1e52130..82205744fe 100644 --- a/src/wp-includes/formatting.php +++ b/src/wp-includes/formatting.php @@ -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. diff --git a/tests/phpunit/tests/formatting/WPTexturize.php b/tests/phpunit/tests/formatting/WPTexturize.php index 102c2a78ab..14048deac6 100644 --- a/tests/phpunit/tests/formatting/WPTexturize.php +++ b/tests/phpunit/tests/formatting/WPTexturize.php @@ -313,8 +313,8 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase { "word ’99’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, ’33% of all students scored less than 50′ 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, ’33 students scored less than 50′ on the test.", ), ); } @@ -1060,12 +1060,12 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase { 'word “4,242.00” word', ), array( - "word '99's word", // Is this correct? - "word ‘99’s word", + "word '99's word", + "word ’99’s word", ), array( "word '99'samsonite", - "word ‘99’samsonite", + "word ’99’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 ‘999 word", ), + array( + "word '99% word", + "word ‘99% word", + ), array( "word '9 word", "word ‘9 word",