Make WordPress Core

Changeset 28761


Ignore:
Timestamp:
06/17/2014 05:40:07 PM (11 years ago)
Author:
wonderboymusic
Message:

wptexturize() adjustments:

  • Only place an apostrophe before a number when it has exactly two digits.
  • Never match '99' with the single prime pattern.
  • Always assume '99' is an abbreviated year at the end of a quotation.
  • Add unit tests.
  • Resolves the unit test broken in [28721] for #8775.

See #26850.

Location:
trunk
Files:
2 edited

Legend:

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

    r28727 r28761  
    101101        $dynamic = array();
    102102
     103        // '99' is an ambiguous case among other patterns; assume it's an abbreviated year at the end of a quotation.
     104        if ( "'" !== $apos && "'" !== $closing_single_quote ) {
     105            $dynamic[ '/\'(\d\d)\'(?=\Z|[.,)}>\-\]]|' . $spaces . ')/' ] = $apos . '$1' . $closing_single_quote;
     106        }
     107
     108        // '99 '99s '99's (apostrophe)  But never '9 or '999 or '99.0.
     109        if ( "'" !== $apos ) {
     110            $dynamic[ '/\'(?=\d\d(?:\Z|(?!\d|[.,]\d)))/' ] = $apos;
     111        }
     112
    103113        // Quoted Numbers like "42" or '42.00'
    104114        if ( '"' !== $opening_quote && '"' !== $closing_quote ) {
     
    107117        if ( "'" !== $opening_single_quote && "'" !== $closing_single_quote ) {
    108118            $dynamic[ '/(?<=\A|' . $spaces . ')\'(\d[\d\.\,]*)\'/' ] = $opening_single_quote . '$1' . $closing_single_quote;
    109         }
    110 
    111         // '99 '99s '99's (apostrophe)
    112         if ( "'" !== $apos ) {
    113             $dynamic[ '/\'(?=\d)/' ] = $apos;
    114119        }
    115120
  • trunk/tests/phpunit/tests/formatting/WPTexturize.php

    r28727 r28761  
    12801280        );
    12811281    }
     1282
     1283    /**
     1284     * Year abbreviations consist of exactly two digits.
     1285     *
     1286     * @ticket 26850
     1287     * @dataProvider data_quotes_and_dashes
     1288     */
     1289    function test_year_abbr( $input, $output ) {
     1290        return $this->assertEquals( $output, wptexturize( $input ) );
     1291    }
     1292
     1293    function data_year_abbr() {
     1294        return array(
     1295            array(
     1296                "word '99 word",
     1297                "word &#8217;99 word",
     1298            ),
     1299            array(
     1300                "word '99. word",
     1301                "word &#8217;99. word",
     1302            ),
     1303            array(
     1304                "word '99, word",
     1305                "word &#8217;99, word",
     1306            ),
     1307            array(
     1308                "word '99; word",
     1309                "word &#8217;99; word",
     1310            ),
     1311            array(
     1312                "word '99' word", // For this pattern, prime doesn't make sense.  Should get apos and a closing quote.
     1313                "word &#8217;99&#8217; word",
     1314            ),
     1315            array(
     1316                "word '99'. word",
     1317                "word &#8217;99&#8217;. word",
     1318            ),
     1319            array(
     1320                "word '99', word",
     1321                "word &#8217;99&#8217;, word",
     1322            ),
     1323            array(
     1324                "word '99.' word",
     1325                "word &#8217;99.&#8217; word",
     1326            ),
     1327            array(
     1328                "word '99",
     1329                "word &#8217;99",
     1330            ),
     1331            array(
     1332                "'99 word",
     1333                "&#8217;99 word",
     1334            ),
     1335            array(
     1336                "word '999 word", // Does not match the apos pattern, should be opening quote.
     1337                "word &#8216;999 word",
     1338            ),
     1339            array(
     1340                "word '9 word",
     1341                "word &#8216;9 word",
     1342            ),
     1343            array(
     1344                "word '99.9 word",
     1345                "word &#8216;99.9 word",
     1346            ),
     1347            array(
     1348                "word '999",
     1349                "word &#8216;999",
     1350            ),
     1351            array(
     1352                "word '9",
     1353                "word &#8216;9",
     1354            ),
     1355            array(
     1356                "in '4 years, 3 months,' Obama cut the deficit",
     1357                "in &#8216;4 years, 3 months,&#8217; Obama cut the deficit",
     1358            ),
     1359            array(
     1360                "testing's '4' through 'quotes'",
     1361                "testing&#8217;s &#8216;4&#8217; through &#8216;quotes&#8217;",
     1362            ),
     1363        );
     1364    }
    12821365}
Note: See TracChangeset for help on using the changeset viewer.