From 013f3f14e36694b1e7bbf3789f6dea8b67df8ec6 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Tue, 10 Jun 2014 02:42:35 +0000 Subject: [PATCH] Fix curly quotes around numbers when applicable. Adds unit tests. Props filosofo, mrmist, aliso, MikeHansenMe, miqrogroove. Fixes #8775. git-svn-id: https://develop.svn.wordpress.org/trunk@28721 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/formatting.php | 8 +++ .../phpunit/tests/formatting/WPTexturize.php | 68 +++++++++++++++---- 2 files changed, 62 insertions(+), 14 deletions(-) diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php index be2292502b..94000b3995 100644 --- a/src/wp-includes/formatting.php +++ b/src/wp-includes/formatting.php @@ -88,6 +88,14 @@ function wptexturize($text) { // Pattern-based replacements of characters. $dynamic = array(); + // Quoted Numbers like "42" or '42.00' + if ( '"' !== $opening_quote && '"' !== $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; + } + // '99 '99s '99's (apostrophe) if ( "'" !== $apos ) { $dynamic[ '/\'(?=\d)/' ] = $apos; diff --git a/tests/phpunit/tests/formatting/WPTexturize.php b/tests/phpunit/tests/formatting/WPTexturize.php index 544e454304..c08c7e19b4 100644 --- a/tests/phpunit/tests/formatting/WPTexturize.php +++ b/tests/phpunit/tests/formatting/WPTexturize.php @@ -154,8 +154,8 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase { function test_wptexturize_quotes_around_numbers() { $this->assertEquals('“12345”', wptexturize('"12345"')); $this->assertEquals('‘12345’', wptexturize('\'12345\'')); - $this->assertEquals('“a 9′ plus a ‘9’, maybe a 9′ ‘9’ ”', wptexturize('"a 9\' plus a \'9\', maybe a 9\' \'9\' "')); - $this->assertEquals('

‘99
‘123’
’tis
‘s’

', wptexturize('

\'99
\'123\'
\'tis
\'s\'

')); + $this->assertEquals('“a 9′ plus a ‘9’, maybe a 9′ ‘9’”', wptexturize('"a 9\' plus a \'9\', maybe a 9\' \'9\'"')); + $this->assertEquals('

’99
‘123’
’tis
‘s’

', wptexturize('

\'99
\'123\'
\'tis
\'s\'

')); } /** @@ -312,22 +312,10 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase { "word '99’s word", // Appears as a separate but logically superfluous pattern in 3.8. "word ’99’s word", ), - array( - "word '99's word", // Due to the logic error, second apos becomes a prime. See ticket #22823 - "word ’99′s word", - ), - array( - "word '99'samsonite", - "word ’99′samsonite", - ), 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.", ), - array( - "word '99' word", // See ticket #8775 - "word ’99′ word", - ), ); } @@ -1026,4 +1014,56 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase { ), ); } + + /** + * Numbers inside of matching quotes get curly quotes instead of apostrophes and primes. + * + * @ticket 8775 + * @dataProvider data_quoted_numbers + */ + function test_quoted_numbers( $input, $output ) { + return $this->assertEquals( $output, wptexturize( $input ) ); + } + + function data_quoted_numbers() { + return array( + array( + 'word "42.00" word', + 'word “42.00” word', + ), + array( + 'word "42.00"word', + 'word “42.00”word', + ), + array( + "word '42.00' word", + "word ‘42.00’ word", + ), + array( + "word '42.00'word", + "word ‘42.00’word", + ), + array( + 'word "42" word', + 'word “42” word', + ), + array( + 'word "42,00" word', + 'word “42,00” word', + ), + array( + 'word "4,242.00" word', + 'word “4,242.00” word', + ), + array( + "word '99's word", // Is this correct? + "word ‘99’s word", + ), + array( + "word '99'samsonite", + "word ‘99’samsonite", + ), + ); + } + }