In wptexturize(), allow dashes before and after curly quotes. Example: This is what she said---"Wow that is cool."

Adds unit tests.

Props adamsilverstein, miqrogroove.
Fixes #20342.


git-svn-id: https://develop.svn.wordpress.org/trunk@28726 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor 2014-06-10 14:21:36 +00:00
parent 66b539bdab
commit 9e347a40c2
2 changed files with 69 additions and 6 deletions

View File

@ -91,8 +91,8 @@ function wptexturize($text) {
$cockney = $cockneyreplace = array();
}
$static_characters = array_merge( array( '---', '...', '``', '\'\'', ' (tm)' ), $cockney );
$static_replacements = array_merge( array( $em_dash, '…', $opening_quote, $closing_quote, ' ™' ), $cockneyreplace );
$static_characters = array_merge( array( '...', '``', '\'\'', ' (tm)' ), $cockney );
$static_replacements = array_merge( array( '…', $opening_quote, $closing_quote, ' ™' ), $cockneyreplace );
$spaces = wp_spaces_regexp();
@ -113,9 +113,9 @@ function wptexturize($text) {
$dynamic[ '/\'(?=\d)/' ] = $apos;
}
// Single quote at start, or preceded by (, {, <, [, ", or spaces.
// 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 or double apostrophes.
@ -133,9 +133,9 @@ function wptexturize($text) {
$dynamic[ '/(?<=\d)\'/' ] = $prime;
}
// Double quote at start, or preceded by (, {, <, [, or spaces, and not followed by spaces.
// 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|[([{<\-]|' . $spaces . ')"(?!' . $spaces . ')/' ] = $opening_quote;
}
// Any remaining double quotes.
@ -149,6 +149,7 @@ function wptexturize($text) {
}
// Dashes and spaces
$dynamic[ '/---/' ] = $em_dash;
$dynamic[ '/(?<=' . $spaces . ')--(?=' . $spaces . ')/' ] = $em_dash;
$dynamic[ '/(?<!xn)--/' ] = $en_dash;
$dynamic[ '/(?<=' . $spaces . ')-(?=' . $spaces . ')/' ] = $en_dash;

View File

@ -1066,4 +1066,66 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase {
);
}
/**
* Quotations should be allowed to have dashes around them.
*
* @ticket 20342
* @dataProvider data_quotes_and_dashes
*/
function test_quotes_and_dashes( $input, $output ) {
return $this->assertEquals( $output, wptexturize( $input ) );
}
function data_quotes_and_dashes() {
return array(
array(
'word---"quote"',
'word&#8212;&#8220;quote&#8221;',
),
array(
'word--"quote"',
'word&#8211;&#8220;quote&#8221;',
),
array(
'word-"quote"',
'word-&#8220;quote&#8221;',
),
array(
"word---'quote'",
"word&#8212;&#8216;quote&#8217;",
),
array(
"word--'quote'",
"word&#8211;&#8216;quote&#8217;",
),
array(
"word-'quote'",
"word-&#8216;quote&#8217;",
),
array(
'"quote"---word',
'&#8220;quote&#8221;&#8212;word',
),
array(
'"quote"--word',
'&#8220;quote&#8221;&#8211;word',
),
array(
'"quote"-word',
'&#8220;quote&#8221;-word',
),
array(
"'quote'---word",
"&#8216;quote&#8217;&#8212;word",
),
array(
"'quote'--word",
"&#8216;quote&#8217;&#8211;word",
),
array(
"'quote'-word",
"&#8216;quote&#8217;-word",
),
);
}
}