WordPress.org

Make WordPress Core

Changeset 28718


Ignore:
Timestamp:
06/10/2014 02:08:05 AM (6 years ago)
Author:
wonderboymusic
Message:

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

Adds unit tests.

Props redsweater, miqrogroove.
Fixes #23185.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/formatting.php

    r28717 r28718  
    8080        }
    8181
    82         $static_characters = array_merge( array( '---', ' -- ', '--', ' - ', 'xn–', '...', '``', '\'\'', ' (tm)' ), $cockney );
    83         $static_replacements = array_merge( array( $em_dash, ' ' . $em_dash . ' ', $en_dash, ' ' . $en_dash . ' ', 'xn--', '…', $opening_quote, $closing_quote, ' ™' ), $cockneyreplace );
     82        $static_characters = array_merge( array( '---', '...', '``', '\'\'', ' (tm)' ), $cockney );
     83        $static_replacements = array_merge( array( $em_dash, '…', $opening_quote, $closing_quote, ' ™' ), $cockneyreplace );
    8484
    8585        $spaces = wp_spaces_regexp();
     
    128128            $dynamic[ '/\'(?=\Z|\.|' . $spaces . ')/' ] = $closing_single_quote;
    129129        }
     130
     131        // Dashes and spaces
     132        $dynamic[ '/(?<=' . $spaces . ')--(?=' . $spaces . ')/' ] = $em_dash;
     133        $dynamic[ '/(?<!xn)--/' ] = $en_dash;
     134        $dynamic[ '/(?<=' . $spaces . ')-(?=' . $spaces . ')/' ] = $en_dash;
    130135
    131136        $dynamic_characters = array_keys( $dynamic );
  • trunk/tests/phpunit/tests/formatting/WPTexturize.php

    r27839 r28718  
    188188     */
    189189    function test_spaces_around_hyphens() {
     190        $nbsp = "\xC2\xA0";
     191
    190192        $this->assertEquals( ' &#8211; ', wptexturize( ' - ' ) );
    191193        $this->assertEquals( '&nbsp;&#8211;&nbsp;', wptexturize( '&nbsp;-&nbsp;' ) );
    192194        $this->assertEquals( ' &#8211;&nbsp;', wptexturize( ' -&nbsp;' ) );
    193195        $this->assertEquals( '&nbsp;&#8211; ', wptexturize( '&nbsp;- ') );
     196        $this->assertEquals( "$nbsp&#8211;$nbsp", wptexturize( "$nbsp-$nbsp" ) );
     197        $this->assertEquals( " &#8211;$nbsp", wptexturize( " -$nbsp" ) );
     198        $this->assertEquals( "$nbsp&#8211; ", wptexturize( "$nbsp- ") );
    194199
    195200        $this->assertEquals( ' &#8212; ', wptexturize( ' -- ' ) );
     
    197202        $this->assertEquals( ' &#8212;&nbsp;', wptexturize( ' --&nbsp;' ) );
    198203        $this->assertEquals( '&nbsp;&#8212; ', wptexturize( '&nbsp;-- ') );
     204        $this->assertEquals( "$nbsp&#8212;$nbsp", wptexturize( "$nbsp--$nbsp" ) );
     205        $this->assertEquals( " &#8212;$nbsp", wptexturize( " --$nbsp" ) );
     206        $this->assertEquals( "$nbsp&#8212; ", wptexturize( "$nbsp-- ") );
    199207    }
    200208
     
    930938            array(
    931939                "word xn&#8211; word",
    932                 "word xn-- word",
     940                "word xn&#8211; word",
    933941            ),
    934942            array(
    935943                "wordxn&#8211;word",
     944                "wordxn&#8211;word",
     945            ),
     946            array(
     947                "wordxn--word",
    936948                "wordxn--word",
    937949            ),
Note: See TracChangeset for help on using the changeset viewer.