From f9bcf40db7ecbc687156d3ec7e68ac7456bc67d6 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Tue, 10 Jun 2014 02:08:05 +0000 Subject: [PATCH] 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 --- src/wp-includes/formatting.php | 9 +++++++-- tests/phpunit/tests/formatting/WPTexturize.php | 14 +++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php index a36129767f..3086a092e8 100644 --- a/src/wp-includes/formatting.php +++ b/src/wp-includes/formatting.php @@ -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[ '/(?assertEquals( ' – ', wptexturize( ' - ' ) ); $this->assertEquals( ' – ', wptexturize( ' - ' ) ); $this->assertEquals( ' – ', wptexturize( ' - ' ) ); $this->assertEquals( ' – ', wptexturize( ' - ') ); + $this->assertEquals( "$nbsp–$nbsp", wptexturize( "$nbsp-$nbsp" ) ); + $this->assertEquals( " –$nbsp", wptexturize( " -$nbsp" ) ); + $this->assertEquals( "$nbsp– ", wptexturize( "$nbsp- ") ); $this->assertEquals( ' — ', wptexturize( ' -- ' ) ); $this->assertEquals( ' — ', wptexturize( ' -- ' ) ); $this->assertEquals( ' — ', wptexturize( ' -- ' ) ); $this->assertEquals( ' — ', wptexturize( ' -- ') ); + $this->assertEquals( "$nbsp—$nbsp", wptexturize( "$nbsp--$nbsp" ) ); + $this->assertEquals( " —$nbsp", wptexturize( " --$nbsp" ) ); + $this->assertEquals( "$nbsp— ", wptexturize( "$nbsp-- ") ); } /** @@ -929,10 +937,14 @@ class Tests_Formatting_WPTexturize extends WP_UnitTestCase { ), array( "word xn– word", - "word xn-- word", + "word xn– word", ), array( "wordxn–word", + "wordxn–word", + ), + array( + "wordxn--word", "wordxn--word", ), );