WordPress.org

Make WordPress Core

Changeset 28721


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

Fix curly quotes around numbers when applicable.

Adds unit tests.

Props filosofo, mrmist, aliso, MikeHansenMe, miqrogroove.
Fixes #8775.

Location:
trunk
Files:
2 edited

Legend:

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

    r28719 r28721  
    8888        // Pattern-based replacements of characters.
    8989        $dynamic = array();
     90
     91        // Quoted Numbers like "42" or '42.00'
     92        if ( '"' !== $opening_quote && '"' !== $closing_quote ) {
     93            $dynamic[ '/(?<=\A|' . $spaces . ')"(\d[\d\.\,]*)"/' ] = $opening_quote . '$1' . $closing_quote;
     94        }
     95        if ( "'" !== $opening_single_quote && "'" !== $closing_single_quote ) {
     96            $dynamic[ '/(?<=\A|' . $spaces . ')\'(\d[\d\.\,]*)\'/' ] = $opening_single_quote . '$1' . $closing_single_quote;
     97        }
    9098
    9199        // '99 '99s '99's (apostrophe)
  • trunk/tests/phpunit/tests/formatting/WPTexturize.php

    r28719 r28721  
    155155        $this->assertEquals('&#8220;12345&#8221;', wptexturize('"12345"'));
    156156        $this->assertEquals('&#8216;12345&#8217;', wptexturize('\'12345\''));
    157         $this->assertEquals('&#8220;a 9&#8242; plus a &#8216;9&#8217;, maybe a 9&#8242; &#8216;9&#8217; &#8221;', wptexturize('"a 9\' plus a \'9\', maybe a 9\' \'9\' "'));
    158         $this->assertEquals('<p>&#8216;99<br />&#8216;123&#8217;<br />&#8217;tis<br />&#8216;s&#8217;</p>', wptexturize('<p>\'99<br />\'123\'<br />\'tis<br />\'s\'</p>'));
     157        $this->assertEquals('&#8220;a 9&#8242; plus a &#8216;9&#8217;, maybe a 9&#8242; &#8216;9&#8217;&#8221;', wptexturize('"a 9\' plus a \'9\', maybe a 9\' \'9\'"'));
     158        $this->assertEquals('<p>&#8217;99<br />&#8216;123&#8217;<br />&#8217;tis<br />&#8216;s&#8217;</p>', wptexturize('<p>\'99<br />\'123\'<br />\'tis<br />\'s\'</p>'));
    159159    }
    160160
     
    314314            ),
    315315            array(
    316                 "word '99's word", // Due to the logic error, second apos becomes a prime.  See ticket #22823
    317                 "word &#8217;99&#8242;s word",
    318             ),
    319             array(
    320                 "word '99'samsonite",
    321                 "word &#8217;99&#8242;samsonite",
    322             ),
    323             array(
    324316                "according to our source, '33% of all students scored less than 50' on the test.", // Apostrophes and primes have priority over quotes
    325317                "according to our source, &#8217;33% of all students scored less than 50&#8242; on the test.",
    326318            ),
    327             array(
    328                 "word '99' word", // See ticket #8775
    329                 "word &#8217;99&#8242; word",
    330             ),
    331319        );
    332320    }
     
    10271015        );
    10281016    }
     1017
     1018    /**
     1019     * Numbers inside of matching quotes get curly quotes instead of apostrophes and primes.
     1020     *
     1021     * @ticket 8775
     1022     * @dataProvider data_quoted_numbers
     1023     */
     1024    function test_quoted_numbers( $input, $output ) {
     1025        return $this->assertEquals( $output, wptexturize( $input ) );
     1026    }
     1027
     1028    function data_quoted_numbers() {
     1029        return array(
     1030            array(
     1031                'word "42.00" word',
     1032                'word &#8220;42.00&#8221; word',
     1033            ),
     1034            array(
     1035                'word "42.00"word',
     1036                'word &#8220;42.00&#8221;word',
     1037            ),
     1038            array(
     1039                "word '42.00' word",
     1040                "word &#8216;42.00&#8217; word",
     1041            ),
     1042            array(
     1043                "word '42.00'word",
     1044                "word &#8216;42.00&#8217;word",
     1045            ),
     1046            array(
     1047                'word "42" word',
     1048                'word &#8220;42&#8221; word',
     1049            ),
     1050            array(
     1051                'word "42,00" word',
     1052                'word &#8220;42,00&#8221; word',
     1053            ),
     1054            array(
     1055                'word "4,242.00" word',
     1056                'word &#8220;4,242.00&#8221; word',
     1057            ),
     1058            array(
     1059                "word '99's word", // Is this correct?
     1060                "word &#8216;99&#8217;s word",
     1061            ),
     1062            array(
     1063                "word '99'samsonite",
     1064                "word &#8216;99&#8217;samsonite",
     1065            ),
     1066        );
     1067    }
     1068
    10291069}
Note: See TracChangeset for help on using the changeset viewer.