WordPress.org

Make WordPress Core

Changeset 32789


Ignore:
Timestamp:
06/16/2015 12:49:45 AM (6 years ago)
Author:
wonderboymusic
Message:

Improve the consistency of punctuation matching in wptexturize().

Adds unit tests.

Props miqrogroove.
Fixes #31886.

Location:
trunk
Files:
2 edited

Legend:

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

    r32788 r32789  
    128128        // '99' and '99" are ambiguous among other patterns; assume it's an abbreviated year at the end of a quotation.
    129129        if ( "'" !== $apos || "'" !== $closing_single_quote ) {
    130             $dynamic[ '/\'(\d\d)\'(?=\Z|[.,)}\-\]]|>|' . $spaces . ')/' ] = $apos . '$1' . $closing_single_quote;
     130            $dynamic[ '/\'(\d\d)\'(?=\Z|[.,:;!?)}\-\]]|>|' . $spaces . ')/' ] = $apos . '$1' . $closing_single_quote;
    131131        }
    132132        if ( "'" !== $apos || '"' !== $closing_quote ) {
    133             $dynamic[ '/\'(\d\d)"(?=\Z|[.,)}\-\]]|>|' . $spaces . ')/' ] = $apos . '$1' . $closing_quote;
     133            $dynamic[ '/\'(\d\d)"(?=\Z|[.,:;!?)}\-\]]|>|' . $spaces . ')/' ] = $apos . '$1' . $closing_quote;
    134134        }
    135135
     
    151151        // Apostrophe in a word.  No spaces, double apostrophes, or other punctuation.
    152152        if ( "'" !== $apos ) {
    153             $dynamic[ '/(?<!' . $spaces . ')\'(?!\Z|[.,:;"\'(){}[\]\-]|&[lg]t;|' . $spaces . ')/' ] = $apos;
     153            $dynamic[ '/(?<!' . $spaces . ')\'(?!\Z|[.,:;!?"\'(){}[\]\-]|&[lg]t;|' . $spaces . ')/' ] = $apos;
    154154        }
    155155
     
    161161        // Single quotes followed by spaces or ending punctuation.
    162162        if ( "'" !== $closing_single_quote ) {
    163             $dynamic[ '/\'(?=\Z|[.,)}\-\]]|&gt;|' . $spaces . ')/' ] = $closing_single_quote;
     163            $dynamic[ '/\'(?=\Z|[.,:;!?)}\-\]]|&gt;|' . $spaces . ')/' ] = $closing_single_quote;
    164164        }
    165165
  • trunk/tests/phpunit/tests/formatting/WPTexturize.php

    r32788 r32789  
    113113        $this->assertEquals('Class of &#8217;99&#8217;s', wptexturize("Class of '99's"));
    114114        $this->assertEquals('&#8216;Class of &#8217;99&#8217;', wptexturize("'Class of '99'"));
     115        $this->assertEquals('&#8216;Class of &#8217;99&#8217; ', wptexturize("'Class of '99' "));
     116        $this->assertEquals('&#8216;Class of &#8217;99&#8217;.', wptexturize("'Class of '99'."));
     117        $this->assertEquals('&#8216;Class of &#8217;99&#8217;, she said', wptexturize("'Class of '99', she said"));
     118        $this->assertEquals('&#8216;Class of &#8217;99&#8217;:', wptexturize("'Class of '99':"));
     119        $this->assertEquals('&#8216;Class of &#8217;99&#8217;;', wptexturize("'Class of '99';"));
     120        $this->assertEquals('&#8216;Class of &#8217;99&#8217;!', wptexturize("'Class of '99'!"));
     121        $this->assertEquals('&#8216;Class of &#8217;99&#8217;?', wptexturize("'Class of '99'?"));
    115122        $this->assertEquals('&#8216;Class of &#8217;99&#8217;s&#8217;', wptexturize("'Class of '99's'"));
    116123        $this->assertEquals('&#8216;Class of &#8217;99&#8217;s&#8217;', wptexturize("'Class of '99&#8217;s'"));
     
    119126        $this->assertEquals('{&#8220;Class of &#8217;99&#8221;}', wptexturize("{\"Class of '99\"}"));
    120127        $this->assertEquals(' &#8220;Class of &#8217;99&#8221; ', wptexturize(" \"Class of '99\" "));
     128        $this->assertEquals(' &#8220;Class of &#8217;99&#8221;.', wptexturize(" \"Class of '99\"."));
     129        $this->assertEquals(' &#8220;Class of &#8217;99&#8221;, she said', wptexturize(" \"Class of '99\", she said"));
     130        $this->assertEquals(' &#8220;Class of &#8217;99&#8221;:', wptexturize(" \"Class of '99\":"));
     131        $this->assertEquals(' &#8220;Class of &#8217;99&#8221;;', wptexturize(" \"Class of '99\";"));
     132        $this->assertEquals(' &#8220;Class of &#8217;99&#8221;!', wptexturize(" \"Class of '99\"!"));
     133        $this->assertEquals(' &#8220;Class of &#8217;99&#8221;?', wptexturize(" \"Class of '99\"?"));
    121134        $this->assertEquals('}&#8221;Class of &#8217;99&#8243;{', wptexturize("}\"Class of '99\"{")); // Not a quotation, may be between two other quotations.
    122135    }
     
    703716            ),
    704717            array(
     718                'test sentence",',
     719                'test sentence&#8221;,',
     720            ),
     721            array(
     722                'test sentence":',
     723                'test sentence&#8221;:',
     724            ),
     725            array(
     726                'test sentence";',
     727                'test sentence&#8221;;',
     728            ),
     729            array(
     730                'test sentence"!',
     731                'test sentence&#8221;!',
     732            ),
     733            array(
     734                'test sentence"?',
     735                'test sentence&#8221;?',
     736            ),
     737            array(
    705738                'test sentence."',
    706739                'test sentence.&#8221;',
     
    746779                "word word', she said",
    747780                "word word&#8217;, she said",
     781            ),
     782            array(
     783                "word word': word",
     784                "word word&#8217;: word",
     785            ),
     786            array(
     787                "word word'; word",
     788                "word word&#8217;; word",
     789            ),
     790            array(
     791                "word word'! word",
     792                "word word&#8217;! word",
     793            ),
     794            array(
     795                "word word'? word",
     796                "word word&#8217;? word",
    748797            ),
    749798            array(
Note: See TracChangeset for help on using the changeset viewer.