diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php index 3086a092e8..be2292502b 100644 --- a/src/wp-includes/formatting.php +++ b/src/wp-includes/formatting.php @@ -180,10 +180,10 @@ function wptexturize($text) { // regular expressions $curl = preg_replace($dynamic_characters, $dynamic_replacements, $curl); - // 9x9 (times) - if ( 1 === preg_match( '/(?<=\d)x\d/', $text ) ) { + // 9x9 (times), but never 0x9999 + if ( 1 === preg_match( '/(?<=\d)x-?\d/', $text ) ) { // Searching for a digit is 10 times more expensive than for the x, so we avoid doing this one! - $curl = preg_replace( '/\b(\d+)x(\d+)\b/', '$1×$2', $curl ); + $curl = preg_replace( '/\b(\d(?(?<=0)[\d\.,]+|[\d\.,]*))x(-?\d[\d\.,]*)\b/', '$1×$2', $curl ); } } diff --git a/tests/phpunit/tests/formatting/WPTexturize.php b/tests/phpunit/tests/formatting/WPTexturize.php index 7e292d33d7..544e454304 100644 --- a/tests/phpunit/tests/formatting/WPTexturize.php +++ b/tests/phpunit/tests/formatting/WPTexturize.php @@ -780,10 +780,30 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase { "12x34", "12×34", ), + array( + "-123x1=-123", + "-123×1=-123", + ), + array( + "-123x-1", + "-123×-1", + ), + array( + "0.675x1=0.675", + "0.675×1=0.675", + ), array( "9 x 9", "9 x 9", ), + array( + "0x70", + "0x70", + ), + array( + "3x2x1x0", + "3x2x1x0", + ), ); }