Make WordPress Core

Ticket #4539: formatting_latest_fixes_all.diff

File formatting_latest_fixes_all.diff, 8.9 KB (added by norbertm, 14 years ago)
  • wp-testcase/test_includes_formatting.php

     
    386386                $this->assertEquals('A dog (“Hubertus”) was sent out.', wptexturize('A dog ("Hubertus") was sent out.'));
    387387        }
    388388       
     389        //WP Ticket #4539
     390        function test_basic_quotes() {
     391                $this->assertEquals('test’s', wptexturize('test\'s'));
     392                $this->assertEquals('test’s', wptexturize('test\'s'));
     393
     394                $this->assertEquals('‘quoted’', wptexturize('\'quoted\''));
     395                $this->assertEquals('“quoted”', wptexturize('"quoted"'));
     396
     397                $this->assertEquals('(‘quoted’)', wptexturize('(\'quoted\')'));
     398                $this->assertEquals('{“quoted”}', wptexturize('{"quoted"}'));
     399
     400                $this->assertEquals('‘qu(ot)ed’', wptexturize('\'qu(ot)ed\''));
     401                $this->assertEquals('“qu{ot}ed”', wptexturize('"qu{ot}ed"'));
     402
     403                $this->assertEquals('‘test’s quoted’', wptexturize('\'test\'s quoted\''));
     404                $this->assertEquals('“test’s quoted”', wptexturize('"test\'s quoted"'));
     405        }
     406       
     407        //WP Ticket #4539
    389408        function test_quotes() {
    390                 $this->knownWPBug(4539);
    391409                $this->assertEquals('“Quoted String”', wptexturize('"Quoted String"'));
    392410                $this->assertEquals('Here is &#8220;<a href="http://example.com">a test with a link</a>&#8221;', wptexturize('Here is "<a href="http://example.com">a test with a link</a>"'));
    393                 $this->assertEquals('Here is &#8220;<a href="http://example.com">a test with a link and a period </a>&#8221;.', wptexturize('Here is "<a href="http://example.com">a test with a link and a period</a>".'));
     411                $this->assertEquals('Here is &#8220;<a href="http://example.com">a test with a link and a period</a>&#8221;.', wptexturize('Here is "<a href="http://example.com">a test with a link and a period</a>".'));
    394412                $this->assertEquals('Here is &#8220;<a href="http://example.com">a test with a link</a>&#8221; and a space.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>" and a space.'));
    395413                $this->assertEquals('Here is &#8220;<a href="http://example.com">a test with a link</a> and some text quoted&#8221;', wptexturize('Here is "<a href="http://example.com">a test with a link</a> and some text quoted"'));
    396414                $this->assertEquals('Here is &#8220;<a href="http://example.com">a test with a link</a>&#8221;, and a comma.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>", and a comma.'));
    397415                $this->assertEquals('Here is &#8220;<a href="http://example.com">a test with a link</a>&#8221;; and a semi-colon.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>"; and a semi-colon.'));
    398416                $this->assertEquals('Here is &#8220;<a href="http://example.com">a test with a link</a>&#8221;- and a dash.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>"- and a dash.'));
    399                 $this->assertEquals('Here is &#8220;<a href="http://example.com">a test with a link</a>&#8221;... and ellipses.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>"... and ellipses.'));
     417                $this->assertEquals('Here is &#8220;<a href="http://example.com">a test with a link</a>&#8221;&#8230; and ellipses.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>"... and ellipses.'));
    400418                $this->assertEquals('Here is &#8220;a test <a href="http://example.com">with a link</a>&#8221;.', wptexturize('Here is "a test <a href="http://example.com">with a link</a>".'));
    401419                $this->assertEquals('Here is &#8220;<a href="http://example.com">a test with a link</a>&#8221;and a work stuck to the end.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>"and a work stuck to the end.'));
    402420                $this->assertEquals('A test with a finishing number, &#8220;like 23&#8221;.', wptexturize('A test with a finishing number, "like 23".'));
    403421                $this->assertEquals('A test with a number, &#8220;like 62&#8221;, is nice to have.', wptexturize('A test with a number, "like 62", is nice to have.'));
    404422        }
    405423       
    406         //WP Ticket #1258
     424        //WP Ticket #4539
    407425        function test_quotes_before_s() {
    408                 $this->knownWPBug(4539);
    409426                $this->assertEquals('test&#8217;s', wptexturize("test's"));
    410427                $this->assertEquals('&#8216;test&#8217;s', wptexturize("'test's"));
    411428                $this->assertEquals('&#8216;test&#8217;s&#8217;', wptexturize("'test's'"));
     
    415432
    416433        //WP Ticket #4539
    417434        function test_quotes_before_numbers() {
    418                 $this->knownWPBug(4539);
    419435                $this->assertEquals('Class of &#8217;99', wptexturize("Class of '99"));
     436                $this->assertEquals('Class of &#8217;99&#8217;s', wptexturize("Class of '99's"));
    420437                $this->assertEquals('&#8216;Class of &#8217;99&#8217;', wptexturize("'Class of '99'"));
     438                $this->assertEquals('&#8216;Class of &#8217;99&#8217;s&#8217;', wptexturize("'Class of '99's'"));
     439                $this->assertEquals('&#8216;Class of &#8217;99&#8217;s&#8217;', wptexturize("'Class of '99&#8217;s'"));
     440                $this->assertEquals('&#8220;Class of 99&#8221;', wptexturize("\"Class of 99\""));
     441                $this->assertEquals('&#8220;Class of &#8217;99&#8221;', wptexturize("\"Class of '99\""));
    421442        }
    422443       
     444        function test_quotes_after_numbers() {
     445                $this->assertEquals('Class of &#8217;99', wptexturize("Class of '99"));
     446        }
     447       
     448        //WP Ticket #15241
    423449        function test_other_html() {
    424                 $this->knownWPBug(15241);
    425                 $this->assertEquals('&#8216;<strong>Quoted Text</strong>&#8217;,', wptexturize("'<strong>Quoted Text</strong>',"));
     450                $this->assertEquals('&#8216;<strong>', wptexturize("'<strong>"));
     451                $this->assertEquals('&#8216;<strong>Quoted Text</strong>&#8217;,', wptexturize('\'<strong>Quoted Text</strong>\','));
    426452                $this->assertEquals('&#8220;<strong>Quoted Text</strong>&#8221;,', wptexturize('"<strong>Quoted Text</strong>",'));
    427453        }
     454       
     455        function test_x() {
     456                $this->assertEquals('14&#215;24', wptexturize("14x24"));
     457        }
     458       
     459        function test_minutes_seconds() {
     460                $this->assertEquals('9&#8242;', wptexturize('9\''));
     461                $this->assertEquals('9&#8243;', wptexturize("9\""));
     462
     463                $this->assertEquals('a 9&#8242; b', wptexturize('a 9\' b'));
     464                $this->assertEquals('a 9&#8243; b', wptexturize("a 9\" b"));
     465               
     466                $this->assertEquals('&#8220;a 9&#8242; b&#8221;', wptexturize('"a 9\' b"'));
     467                $this->assertEquals('&#8216;a 9&#8243; b&#8217;', wptexturize("'a 9\" b'"));
     468        }
    428469}
    429470
    430471class TestCleanUrl extends WPTestCase {
  • wordpress/wp-includes/formatting.php

     
    5656                $static_characters = array_merge(array('---', ' -- ', '--', ' - ', 'xn&#8211;', '...', '``', '\'\'', ' (tm)'), $cockney);
    5757                $static_replacements = array_merge(array('&#8212;', ' &#8212; ', '&#8211;', ' &#8211; ', 'xn--', '&#8230;', $opening_quote, $closing_quote, ' &#8482;'), $cockneyreplace);
    5858
    59                 $dynamic_characters = array('/\'(\d\d(?:&#8217;|\')?s)/', '/\'(\d)/', '/(\s|\A|[([{<]|")\'/', '/(\d)"/', '/(\d)\'/', '/(\S)\'([^\'\s])/', '/(\s|\A|[([{<])"(?!\s)/', '/"(\s|\S|\Z)/', '/\'([\s.]|\Z)/', '/\b(\d+)x(\d+)\b/');
    60                 $dynamic_replacements = array('&#8217;$1','&#8217;$1', '$1&#8216;', '$1&#8243;', '$1&#8242;', '$1&#8217;$2', '$1' . $opening_quote . '$2', $closing_quote . '$1', '&#8217;$1', '$1&#215;$2');
    61 
     59                $dynamic_map = array(
     60                        '/\'(\d)/' => '&#8217;$1', // '99
     61                       
     62                        '/\'([^\']*)\'([^\']*)\'/' => '&#8216;$1&#8217;$2&#8217;', // 'test's'
     63                       
     64                        '/\'([^\']*)\'/' => '&#8216;$1&#8217;', // 'asd'
     65                        '/"([^"]*)"/' => $opening_quote . '$1' . $closing_quote, // "qwe"
     66                       
     67                        '/(\w)\'(\w)/' => '$1&#8217;$2', // test's
     68                       
     69                        '/(\d)"/' => '$1&#8243;', // 9" -> 9″
     70                        '/(\d)\'/' => '$1&#8242;', // 9' -> 9′
     71                       
     72                        '/\b(\d+)x(\d+)\b/' => '$1&#215;$2' // 10. 97x34 => 97×34
     73                );
     74               
     75                $dynamic_characters = array_keys($dynamic_map);
     76                $dynamic_replacements = array_values($dynamic_map);
     77               
    6278                $static_setup = true;
    6379        }
    6480
     
    6985
    7086        $no_texturize_tags_stack = array();
    7187        $no_texturize_shortcodes_stack = array();
     88       
     89        $single_quote_state = '&#8216;';
     90        $doube_quote_state = $opening_quote;
    7291
    7392        for ( $i = 0; $i < $stop; $i++ ) {
    7493                $curl = $textarr[$i];
     
    8099                        $curl = str_replace($static_characters, $static_replacements, $curl);
    81100                        // regular expressions
    82101                        $curl = preg_replace($dynamic_characters, $dynamic_replacements, $curl);
     102                        // quotes that span multiple tags & shortcodes
     103                        while (($pos = strpos($curl, '\'')) !== FALSE) {
     104                                $curl = preg_replace('/\'/', $single_quote_state, $curl);
     105                                $single_quote_state = (($single_quote_state == '&#8216;') ? '&#8217;' : '&#8216;');
     106                        }
     107                        while (($pos = strpos($curl, '"')) !== FALSE) {
     108                                $curl = preg_replace('/"/', $doube_quote_state, $curl);
     109                                $doube_quote_state = (($doube_quote_state == $opening_quote) ? $closing_quote : $opening_quote);
     110                        }
    83111                } elseif (!empty($curl)) {
    84112                        /*
    85113                         * Only call _wptexturize_pushpop_element if first char is correct