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
This commit is contained in:
parent
ce59109919
commit
013f3f14e3
|
@ -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;
|
||||
|
|
|
@ -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('<p>‘99<br />‘123’<br />’tis<br />‘s’</p>', wptexturize('<p>\'99<br />\'123\'<br />\'tis<br />\'s\'</p>'));
|
||||
$this->assertEquals('“a 9′ plus a ‘9’, maybe a 9′ ‘9’”', wptexturize('"a 9\' plus a \'9\', maybe a 9\' \'9\'"'));
|
||||
$this->assertEquals('<p>’99<br />‘123’<br />’tis<br />‘s’</p>', wptexturize('<p>\'99<br />\'123\'<br />\'tis<br />\'s\'</p>'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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",
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue