Improve the consistency of punctuation matching in wptexturize()
.
Adds unit tests. Props miqrogroove. Fixes #31886. git-svn-id: https://develop.svn.wordpress.org/trunk@32789 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
40bb9aa3d9
commit
1e8fb99ebd
@ -127,10 +127,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.
|
||||
@ -150,7 +150,7 @@ function wptexturize( $text, $reset = false ) {
|
||||
|
||||
// Apostrophe in a word. No spaces, double apostrophes, or other punctuation.
|
||||
if ( "'" !== $apos ) {
|
||||
$dynamic[ '/(?<!' . $spaces . ')\'(?!\Z|[.,:;"\'(){}[\]\-]|&[lg]t;|' . $spaces . ')/' ] = $apos;
|
||||
$dynamic[ '/(?<!' . $spaces . ')\'(?!\Z|[.,:;!?"\'(){}[\]\-]|&[lg]t;|' . $spaces . ')/' ] = $apos;
|
||||
}
|
||||
|
||||
// 9' (prime)
|
||||
@ -160,7 +160,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|[.,:;!?)}\-\]]|>|' . $spaces . ')/' ] = $closing_single_quote;
|
||||
}
|
||||
|
||||
$dynamic_characters['apos'] = array_keys( $dynamic );
|
||||
|
@ -112,12 +112,25 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase {
|
||||
$this->assertEquals('Class of ’99', wptexturize("Class of '99"));
|
||||
$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’, she said', wptexturize("'Class of '99', she said"));
|
||||
$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’s’', wptexturize("'Class of '99's'"));
|
||||
$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\"."));
|
||||
$this->assertEquals(' “Class of ’99”, she said', wptexturize(" \"Class of '99\", she said"));
|
||||
$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.
|
||||
}
|
||||
|
||||
@ -701,6 +714,26 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase {
|
||||
'test sentence".',
|
||||
'test sentence”.',
|
||||
),
|
||||
array(
|
||||
'test sentence",',
|
||||
'test sentence”,',
|
||||
),
|
||||
array(
|
||||
'test sentence":',
|
||||
'test sentence”:',
|
||||
),
|
||||
array(
|
||||
'test sentence";',
|
||||
'test sentence”;',
|
||||
),
|
||||
array(
|
||||
'test sentence"!',
|
||||
'test sentence”!',
|
||||
),
|
||||
array(
|
||||
'test sentence"?',
|
||||
'test sentence”?',
|
||||
),
|
||||
array(
|
||||
'test sentence."',
|
||||
'test sentence.”',
|
||||
@ -746,6 +779,22 @@ 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",
|
||||
|
Loading…
Reference in New Issue
Block a user