In `wptexturize()`, treat ` ` like whitespace when texturizing hyphens.

Adds unit tests.

Props redsweater, miqrogroove.
Fixes #23185.


git-svn-id: https://develop.svn.wordpress.org/trunk@28718 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor 2014-06-10 02:08:05 +00:00
parent db7816dd0c
commit f9bcf40db7
2 changed files with 20 additions and 3 deletions

View File

@ -79,8 +79,8 @@ function wptexturize($text) {
$cockney = $cockneyreplace = array();
}
$static_characters = array_merge( array( '---', ' -- ', '--', ' - ', 'xn–', '...', '``', '\'\'', ' (tm)' ), $cockney );
$static_replacements = array_merge( array( $em_dash, ' ' . $em_dash . ' ', $en_dash, ' ' . $en_dash . ' ', 'xn--', '…', $opening_quote, $closing_quote, ' ™' ), $cockneyreplace );
$static_characters = array_merge( array( '---', '...', '``', '\'\'', ' (tm)' ), $cockney );
$static_replacements = array_merge( array( $em_dash, '…', $opening_quote, $closing_quote, ' ™' ), $cockneyreplace );
$spaces = wp_spaces_regexp();
@ -128,6 +128,11 @@ function wptexturize($text) {
$dynamic[ '/\'(?=\Z|\.|' . $spaces . ')/' ] = $closing_single_quote;
}
// Dashes and spaces
$dynamic[ '/(?<=' . $spaces . ')--(?=' . $spaces . ')/' ] = $em_dash;
$dynamic[ '/(?<!xn)--/' ] = $en_dash;
$dynamic[ '/(?<=' . $spaces . ')-(?=' . $spaces . ')/' ] = $en_dash;
$dynamic_characters = array_keys( $dynamic );
$dynamic_replacements = array_values( $dynamic );
}

View File

@ -187,15 +187,23 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase {
* @ticket 23185
*/
function test_spaces_around_hyphens() {
$nbsp = "\xC2\xA0";
$this->assertEquals( ' &#8211; ', wptexturize( ' - ' ) );
$this->assertEquals( '&nbsp;&#8211;&nbsp;', wptexturize( '&nbsp;-&nbsp;' ) );
$this->assertEquals( ' &#8211;&nbsp;', wptexturize( ' -&nbsp;' ) );
$this->assertEquals( '&nbsp;&#8211; ', wptexturize( '&nbsp;- ') );
$this->assertEquals( "$nbsp&#8211;$nbsp", wptexturize( "$nbsp-$nbsp" ) );
$this->assertEquals( " &#8211;$nbsp", wptexturize( " -$nbsp" ) );
$this->assertEquals( "$nbsp&#8211; ", wptexturize( "$nbsp- ") );
$this->assertEquals( ' &#8212; ', wptexturize( ' -- ' ) );
$this->assertEquals( '&nbsp;&#8212;&nbsp;', wptexturize( '&nbsp;--&nbsp;' ) );
$this->assertEquals( ' &#8212;&nbsp;', wptexturize( ' --&nbsp;' ) );
$this->assertEquals( '&nbsp;&#8212; ', wptexturize( '&nbsp;-- ') );
$this->assertEquals( "$nbsp&#8212;$nbsp", wptexturize( "$nbsp--$nbsp" ) );
$this->assertEquals( " &#8212;$nbsp", wptexturize( " --$nbsp" ) );
$this->assertEquals( "$nbsp&#8212; ", wptexturize( "$nbsp-- ") );
}
/**
@ -929,10 +937,14 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase {
),
array(
"word xn&#8211; word",
"word xn-- word",
"word xn&#8211; word",
),
array(
"wordxn&#8211;word",
"wordxn&#8211;word",
),
array(
"wordxn--word",
"wordxn--word",
),
);