From ff3644a220458b1f74c75b51df453102ae38e6d3 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Thu, 3 Jul 2014 16:21:18 +0000 Subject: [PATCH] Fix texturization of quotes when enclosed by angle brackets. props miqrogroove. fixes #28718. git-svn-id: https://develop.svn.wordpress.org/trunk@28971 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/formatting.php | 13 ++- .../phpunit/tests/formatting/WPTexturize.php | 99 ++++++++++++------- 2 files changed, 69 insertions(+), 43 deletions(-) diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php index 540d3a32b4..1cdd029d4d 100644 --- a/src/wp-includes/formatting.php +++ b/src/wp-includes/formatting.php @@ -104,11 +104,10 @@ function wptexturize($text, $reset = false) { // '99' and '99" are ambiguous 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; + $dynamic[ '/\'(\d\d)\'(?=\Z|[.,)}\-\]]|>|' . $spaces . ')/' ] = $apos . '$1' . $closing_single_quote; } - if ( "'" !== $apos || '"' !== $closing_quote ) { - $dynamic[ '/\'(\d\d)"(?=\Z|[.,)}>\-\]]|' . $spaces . ')/' ] = $apos . '$1' . $closing_quote; + $dynamic[ '/\'(\d\d)"(?=\Z|[.,)}\-\]]|>|' . $spaces . ')/' ] = $apos . '$1' . $closing_quote; } // '99 '99s '99's (apostrophe) But never '9 or '99% or '999 or '99.0. @@ -126,12 +125,12 @@ function wptexturize($text, $reset = false) { // Single quote at start, or preceded by (, {, <, [, ", -, or spaces. if ( "'" !== $opening_single_quote ) { - $dynamic[ '/(?<=\A|[([{<"\-]|' . $spaces . ')\'/' ] = $opening_single_quote; + $dynamic[ '/(?<=\A|[([{"\-]|<|' . $spaces . ')\'/' ] = $opening_single_quote; } // Apostrophe in a word. No spaces, double apostrophes, or other punctuation. if ( "'" !== $apos ) { - $dynamic[ '/(?[\]\-]|' . $spaces . ')/' ] = $apos; + $dynamic[ '/(?\-\]]|' . $spaces . ')/' ] = $closing_single_quote; + $dynamic[ '/\'(?=\Z|[.,)}\-\]]|>|' . $spaces . ')/' ] = $closing_single_quote; } // Dashes and spaces diff --git a/tests/phpunit/tests/formatting/WPTexturize.php b/tests/phpunit/tests/formatting/WPTexturize.php index 8228209447..01dfa00c05 100644 --- a/tests/phpunit/tests/formatting/WPTexturize.php +++ b/tests/phpunit/tests/formatting/WPTexturize.php @@ -117,6 +117,9 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase { $this->assertEquals('‘Class of ’99’s’', wptexturize("'Class of '99’s'")); //$this->assertEquals('“Class of 99”', wptexturize("\"Class of 99\"")); $this->assertEquals('“Class of ’99”', wptexturize("\"Class of '99\"")); + $this->assertEquals('{“Class of ’99”}', wptexturize("{\"Class of '99\"}")); + $this->assertEquals(' “Class of ’99” ', wptexturize(" \"Class of '99\" ")); + $this->assertEquals('}”Class of ’99″{', wptexturize("}\"Class of '99\"{")); // Not a quotation, may be between two other quotations. } function test_quotes_after_numbers() { @@ -346,12 +349,12 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase { "word [‘word word", ), array( - "word <'word word", // Invalid HTML input? - "word <‘word word", + "word <'word word", // Invalid HTML input triggers the apos in a word pattern. + "word <’word word", ), array( - "word <'word word", // Valid HTML input triggers the apos in a word pattern - "word <’word word", + "word <'word word", // Valid HTML input makes curly quotes. + "word <‘word word", ), array( "word {'word word", @@ -375,11 +378,11 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase { ), array( "word<'word word", - "word<‘word word", + "word<’word word", ), array( "word<'word word", - "word<’word word", + "word<‘word word", ), array( "word{'word word", @@ -402,12 +405,12 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase { "word [‘ word word", ), array( - "word <' word word", // Invalid HTML input? - "word <‘ word word", + "word <' word word", + "word <’ word word", ), array( - "word <' word word", // Valid HTML input triggers the closing single quote here - "word <’ word word", + "word <' word word", + "word <‘ word word", ), array( "word {' word word", @@ -431,11 +434,11 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase { ), array( "word<' word word", - "word<‘ word word", + "word<’ word word", ), array( "word<' word word", - "word<’ word word", + "word<‘ word word", ), array( "word{' word word", @@ -533,34 +536,30 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase { "word word’s word", ), array( - "word word'. word", // Quotes with outside punctuation could end with apostrophes instead of closing quotes (may affect i18n) - "word word’. word", + "word'[ word", // Apostrophes are never followed by opening punctuation. + "word'[ word", ), array( - "word ]'. word", - "word ]’. word", + "word'( word", + "word'( word", ), array( - "word )'. word", - "word )’. word", + "word'{ word", + "word'{ word", ), array( - "word }'. word", - "word }’. word", + "word'< word", + "word'< word", ), array( - "word >'. word", // Not tested - "word >’. word", - ), - array( - "word >'. word", - "word >’. word", + "word'< word", // Invalid HTML input does trigger the apos pattern. + "word’< word", ), ); } /** - * Double quote after a space or ([{< becomes “ (opening_quote) if not followed by spaces + * Double quote after a space or ([-{< becomes “ (opening_quote) if not followed by spaces * * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail. * @@ -586,17 +585,25 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase { 'word [“word word', ), array( - 'word <"word word', // Invalid HTML input? - 'word <“word word', + 'word <"word word', // Invalid HTML input triggers the closing quote pattern. + 'word <”word word', ), array( - 'word <"word word', // Valid HTML input triggers the closing quote pattern - 'word <”word word', + 'word <"word word', + 'word <“word word', ), array( 'word {"word word', 'word {“word word', ), + array( + 'word -"word word', + 'word -“word word', + ), + array( + 'word-"word word', + 'word-“word word', + ), array( '"word word', '“word word', @@ -610,12 +617,12 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase { 'word[“word word', ), array( - 'word<"word word', // Invalid HTML input? - 'word<“word word', + 'word<"word word', + 'word<”word word', ), array( - 'word<"word word', // Valid HTML input triggers the closing quote pattern - 'word<”word word', + 'word<"word word', + 'word<“word word', ), array( 'word{"word word', @@ -698,7 +705,7 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase { } /** - * Test that single quotes followed by a space or a period become ’ (closing_single_quote) + * Test that single quotes followed by a space or .,-)}]> become ’ (closing_single_quote) * * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail. * @@ -727,6 +734,26 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase { "word word', she said", "word word’, she said", ), + array( + "word word'- word", + "word word’- word", + ), + array( + "word word') word", + "word word’) word", + ), + array( + "word word'} word", + "word word’} word", + ), + array( + "word word'] word", + "word word’] word", + ), + array( + "word word'> word", + "word word’> word", + ), array( "word word'", "word word’",