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
This commit is contained in:
Sergey Biryukov 2014-07-03 16:21:18 +00:00
parent 09efb2dab9
commit ff3644a220
2 changed files with 69 additions and 43 deletions

View File

@ -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|[([{"\-]|&lt;|' . $spaces . ')\'/' ] = $opening_single_quote;
}
// Apostrophe in a word. No spaces, double apostrophes, or other punctuation.
if ( "'" !== $apos ) {
$dynamic[ '/(?<!' . $spaces . ')\'(?!\Z|[.,:;"\'(){}<>[\]\-]|' . $spaces . ')/' ] = $apos;
$dynamic[ '/(?<!' . $spaces . ')\'(?!\Z|[.,:;"\'(){}[\]\-]|&[lg]t;|' . $spaces . ')/' ] = $apos;
}
// 9" (double prime)
@ -146,7 +145,7 @@ function wptexturize($text, $reset = false) {
// Double quote at start, or preceded by (, {, <, [, -, or spaces, and not followed by spaces.
if ( '"' !== $opening_quote ) {
$dynamic[ '/(?<=\A|[([{<\-]|' . $spaces . ')"(?!' . $spaces . ')/' ] = $opening_quote;
$dynamic[ '/(?<=\A|[([{\-]|&lt;|' . $spaces . ')"(?!' . $spaces . ')/' ] = $opening_quote;
}
// Any remaining double quotes.
@ -156,7 +155,7 @@ function wptexturize($text, $reset = false) {
// Single quotes followed by spaces or ending punctuation.
if ( "'" !== $closing_single_quote ) {
$dynamic[ '/\'(?=\Z|[.,)}>\-\]]|' . $spaces . ')/' ] = $closing_single_quote;
$dynamic[ '/\'(?=\Z|[.,)}\-\]]|&gt;|' . $spaces . ')/' ] = $closing_single_quote;
}
// Dashes and spaces

View File

@ -117,6 +117,9 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase {
$this->assertEquals('&#8216;Class of &#8217;99&#8217;s&#8217;', wptexturize("'Class of '99&#8217;s'"));
//$this->assertEquals('&#8220;Class of 99&#8221;', wptexturize("\"Class of 99\""));
$this->assertEquals('&#8220;Class of &#8217;99&#8221;', wptexturize("\"Class of '99\""));
$this->assertEquals('{&#8220;Class of &#8217;99&#8221;}', wptexturize("{\"Class of '99\"}"));
$this->assertEquals(' &#8220;Class of &#8217;99&#8221; ', wptexturize(" \"Class of '99\" "));
$this->assertEquals('}&#8221;Class of &#8217;99&#8243;{', 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 [&#8216;word word",
),
array(
"word <'word word", // Invalid HTML input?
"word <&#8216;word word",
"word <'word word", // Invalid HTML input triggers the apos in a word pattern.
"word <&#8217;word word",
),
array(
"word &lt;'word word", // Valid HTML input triggers the apos in a word pattern
"word &lt;&#8217;word word",
"word &lt;'word word", // Valid HTML input makes curly quotes.
"word &lt;&#8216;word word",
),
array(
"word {'word word",
@ -375,11 +378,11 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase {
),
array(
"word<'word word",
"word<&#8216;word word",
"word<&#8217;word word",
),
array(
"word&lt;'word word",
"word&lt;&#8217;word word",
"word&lt;&#8216;word word",
),
array(
"word{'word word",
@ -402,12 +405,12 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase {
"word [&#8216; word word",
),
array(
"word <' word word", // Invalid HTML input?
"word <&#8216; word word",
"word <' word word",
"word <&#8217; word word",
),
array(
"word &lt;' word word", // Valid HTML input triggers the closing single quote here
"word &lt;&#8217; word word",
"word &lt;' word word",
"word &lt;&#8216; word word",
),
array(
"word {' word word",
@ -431,11 +434,11 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase {
),
array(
"word<' word word",
"word<&#8216; word word",
"word<&#8217; word word",
),
array(
"word&lt;' word word",
"word&lt;&#8217; word word",
"word&lt;&#8216; word word",
),
array(
"word{' word word",
@ -533,34 +536,30 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase {
"word word&#8217;s word",
),
array(
"word word'. word", // Quotes with outside punctuation could end with apostrophes instead of closing quotes (may affect i18n)
"word word&#8217;. word",
"word'[ word", // Apostrophes are never followed by opening punctuation.
"word'[ word",
),
array(
"word ]'. word",
"word ]&#8217;. word",
"word'( word",
"word'( word",
),
array(
"word )'. word",
"word )&#8217;. word",
"word'{ word",
"word'{ word",
),
array(
"word }'. word",
"word }&#8217;. word",
"word'&lt; word",
"word'&lt; word",
),
array(
"word >'. word", // Not tested
"word >&#8217;. word",
),
array(
"word &gt;'. word",
"word &gt;&#8217;. word",
"word'< word", // Invalid HTML input does trigger the apos pattern.
"word&#8217;< word",
),
);
}
/**
* Double quote after a space or ([{< becomes &#8220; (opening_quote) if not followed by spaces
* Double quote after a space or ([-{< becomes &#8220; (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 [&#8220;word word',
),
array(
'word <"word word', // Invalid HTML input?
'word <&#8220;word word',
'word <"word word', // Invalid HTML input triggers the closing quote pattern.
'word <&#8221;word word',
),
array(
'word &lt;"word word', // Valid HTML input triggers the closing quote pattern
'word &lt;&#8221;word word',
'word &lt;"word word',
'word &lt;&#8220;word word',
),
array(
'word {"word word',
'word {&#8220;word word',
),
array(
'word -"word word',
'word -&#8220;word word',
),
array(
'word-"word word',
'word-&#8220;word word',
),
array(
'"word word',
'&#8220;word word',
@ -610,12 +617,12 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase {
'word[&#8220;word word',
),
array(
'word<"word word', // Invalid HTML input?
'word<&#8220;word word',
'word<"word word',
'word<&#8221;word word',
),
array(
'word&lt;"word word', // Valid HTML input triggers the closing quote pattern
'word&lt;&#8221;word word',
'word&lt;"word word',
'word&lt;&#8220;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 &#8217; (closing_single_quote)
* Test that single quotes followed by a space or .,-)}]> become &#8217; (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&#8217;, she said",
),
array(
"word word'- word",
"word word&#8217;- word",
),
array(
"word word') word",
"word word&#8217;) word",
),
array(
"word word'} word",
"word word&#8217;} word",
),
array(
"word word'] word",
"word word&#8217;] word",
),
array(
"word word'&gt; word",
"word word&#8217;&gt; word",
),
array(
"word word'",
"word word&#8217;",