WordPress.org

Make WordPress Core

Ticket #4539: dev-snapshot-2010-11-20.php.diff

File dev-snapshot-2010-11-20.php.diff, 11.0 KB (added by norbertm, 9 years ago)
  • wordpress/wp-includes/formatting.php

     
    5656                $static_characters = array_merge(array('---', ' -- ', '--', ' - ', 'xn–', '...', '``', '\'\'', ' (tm)'), $cockney);
    5757                $static_replacements = array_merge(array('—', ' — ', '–', ' – ', 'xn--', '…', $opening_quote, $closing_quote, ' ™'), $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');
     59                $dynamic_map = array(
     60                        '/([\A\s])\'(\d)/' => '$1&#8217;$2', // '99
    6161
     62                        '/([\w\]})])\'([\w])/' => '$1&#8217;$2', // test's
     63
     64                        '/\'([^\']*)\'/' => '&#8216;$1&#8217;', // 'asd'
     65                        '/"([^"]*)"/' => $opening_quote . '$1' . $closing_quote, // "qwe"
     66
     67                        '/(\d)\'/' => '$1&#8242;', // 9'
     68                        '/(\d)"/' => '$1&#8243;', // 9"
     69
     70                        '/\b(\d+)x(\d+)\b/' => '$1&#215;$2' // 97x34
     71                );
     72
     73                $dynamic_characters = array_keys( $dynamic_map );
     74                $dynamic_replacements = array_values( $dynamic_map );
     75
    6276                $static_setup = true;
    6377        }
    6478
     
    7084        $no_texturize_tags_stack = array();
    7185        $no_texturize_shortcodes_stack = array();
    7286
     87        $single_quote_state = '&#8216;';
     88        $double_quote_state = $opening_quote;
     89
     90        $text_node_count = 0;
     91        $whitespace_before_last_tag = false;
     92
    7393        for ( $i = 0; $i < $stop; $i++ ) {
    7494                $curl = $textarr[$i];
    7595
     
    7898                        // This is not a tag, nor is the texturization disabled
    7999                        // static strings
    80100                        $curl = str_replace($static_characters, $static_replacements, $curl);
     101                        // quotes after tags, e.g. <b>somebody</b>'s
     102                        if ( ( $text_node_count > 0 ) && ( ! $whitespace_before_last_tag ) ) {
     103                                $curl = preg_replace( '/^(\')/', '&#8217;', $curl );
     104                        }
    81105                        // regular expressions
    82106                        $curl = preg_replace($dynamic_characters, $dynamic_replacements, $curl);
     107                        // quotes that span multiple tags & shortcodes
     108                        while ( ( $pos = strpos( $curl, '\'' ) ) !== false ) {
     109                                $curl = preg_replace( '/\'/', $single_quote_state, $curl );
     110                                $single_quote_state = ( ( '&#8216;' == $single_quote_state ) ? '&#8217;' : '&#8216;' );
     111                        }
     112                        while ( ( $pos = strpos($curl, '"' ) ) !== false ) {
     113                                $curl = preg_replace( '/"/', $double_quote_state, $curl );
     114                                $double_quote_state = ( $opening_quote == $double_quote_state ) ? $closing_quote : $opening_quote;
     115                        }
     116                        // stats for quotes after tags above
     117                        $text_node_count++;
     118                        $whitespace_before_last_tag = ( preg_match('/\s$/', $curl) > 0 );
    83119                } elseif (!empty($curl)) {
    84120                        /*
    85121                         * Only call _wptexturize_pushpop_element if first char is correct
  • wp-testcase/test_includes_formatting.php

     
    385385        function test_bracketed_quotes_3810() {
    386386                $this->assertEquals('A dog (&#8220;Hubertus&#8221;) was sent out.', wptexturize('A dog ("Hubertus") was sent out.'));
    387387        }
    388        
     388
    389389        //WP Ticket #4539
    390390        function test_basic_quotes() {
     391                $this->assertNotEquals('&#8216;&#8217;', wptexturize("''")); // this does not work as expected due to a static replacement
     392                $this->assertEquals('&#8220;&#8221;', wptexturize('""'));
     393                $this->assertEquals('&#8220;&#8221;', wptexturize("``''")); // this is what causes '' to fail
     394                $this->assertEquals('&#8216; &#8217;', wptexturize("' '"));
     395                $this->assertEquals('&#8220; &#8221;', wptexturize('" "'));
     396                $this->assertEquals('&#8216;<img src="">&#8217;', wptexturize('\'<img src="">\''));
     397                $this->assertEquals('&#8220;<img src="">&#8221;', wptexturize('"<img src="">"'));
     398                $this->assertEquals('Peter&#8217;s photo: &#8216;<img src="">&#8217;', wptexturize('Peter\'s photo: \'<img src="">\''));
     399                $this->assertEquals('Peter&#8217;s photo: &#8220;<img src="">&#8221;', wptexturize('Peter\'s photo: "<img src="">"'));
     400
    391401                $this->assertEquals('test&#8217;s', wptexturize('test\'s'));
    392402                $this->assertEquals('test&#8217;s', wptexturize('test\'s'));
    393403
    394404                $this->assertEquals('&#8216;quoted&#8217;', wptexturize('\'quoted\''));
    395405                $this->assertEquals('&#8220;quoted&#8221;', wptexturize('"quoted"'));
     406                $this->assertEquals('&#8216;quoted&#8217;s&#8217;', wptexturize('\'quoted\'s\''));
     407                $this->assertEquals('&#8220;quoted&#8217;s&#8221;', wptexturize('"quoted\'s"'));
    396408
    397409                $this->assertEquals('(&#8216;quoted&#8217;)', wptexturize('(\'quoted\')'));
    398410                $this->assertEquals('{&#8220;quoted&#8221;}', wptexturize('{"quoted"}'));
     411                $this->assertEquals('(&#8216;quoted&#8217;s&#8217;)', wptexturize('(\'quoted\'s\')'));
     412                $this->assertEquals('{&#8220;quoted&#8217;s&#8221;}', wptexturize('{"quoted\'s"}'));
    399413
    400414                $this->assertEquals('&#8216;qu(ot)ed&#8217;', wptexturize('\'qu(ot)ed\''));
    401415                $this->assertEquals('&#8220;qu{ot}ed&#8221;', wptexturize('"qu{ot}ed"'));
     416                $this->assertEquals('&#8216;qu(ot)ed&#8217;s&#8217;', wptexturize('\'qu(ot)ed\'s\''));
     417                $this->assertEquals('&#8220;qu{ot}ed&#8217;s&#8221;', wptexturize('"qu{ot}ed\'s"'));
     418                $this->assertEquals('&#8216;qu(ot)&#8217;s&#8217;', wptexturize('\'qu(ot)\'s\''));
     419                $this->assertEquals('&#8220;qu{ot}&#8217;s&#8221;', wptexturize('"qu{ot}\'s"'));
     420                $this->assertEquals('&#8220;qu[ot]&#8217;s&#8221;', wptexturize('"qu[ot]\'s"'));
    402421
    403422                $this->assertEquals('&#8216;test&#8217;s quoted&#8217;', wptexturize('\'test\'s quoted\''));
    404423                $this->assertEquals('&#8220;test&#8217;s quoted&#8221;', wptexturize('"test\'s quoted"'));
     
    410429                        'That means every moment you&#8217;re working on something without it being in the public it&#8217;s actually dying.',
    411430                        wptexturize("That means every moment you're working on something without it being in the public it's actually dying.")
    412431                );
     432                $this->assertEquals(
     433                        '&#8216;That means every moment you&#8217;re working on something without it being in the public it&#8217;s actually dying.&#8217;',
     434                        wptexturize("'That means every moment you're working on something without it being in the public it's actually dying.'")
     435                );
     436                $this->assertEquals(
     437                        '&#8220;That means every moment you&#8217;re working on something without it being in the public it&#8217;s actually dying.&#8221;',
     438                        wptexturize("\"That means every moment you're working on something without it being in the public it's actually dying.\"")
     439                );
     440                $this->assertEquals(
     441                        'That means every moment you&#8217;re working on &#8216;something&#8217; without it being in the public it&#8217;s actually dying.',
     442                        wptexturize("That means every moment you're working on 'something' without it being in the public it's actually dying.")
     443                );
     444                $this->assertEquals(
     445                        'That means every moment you&#8217;re working on &#8220;something&#8221; without it being in the public it&#8217;s actually dying.',
     446                        wptexturize("That means every moment you're working on \"something\" without it being in the public it's actually dying.")
     447                );
    413448        }
    414449
    415450        //WP Ticket #4539
     
    451486                $this->assertEquals('&#8220;Class of 99&#8221;', wptexturize("\"Class of 99\""));
    452487                $this->assertEquals('&#8220;Class of &#8217;99&#8221;', wptexturize("\"Class of '99\""));
    453488        }
    454        
    455         function test_quotes_after_numbers() {
    456                 $this->assertEquals('Class of &#8217;99', wptexturize("Class of '99"));
    457         }
    458        
     489
    459490        //WP Ticket #15241
    460491        function test_other_html() {
    461492                $this->knownWPBug(15241);
    462493                $this->assertEquals('&#8216;<strong>', wptexturize("'<strong>"));
     494                $this->assertEquals('&#8220;<strong>', wptexturize('"<strong>'));
     495                $this->assertEquals('&#8216;<strong></strong>&#8217;', wptexturize("'<strong></strong>'"));
     496                $this->assertEquals('&#8220;<strong></strong>&#8221;', wptexturize('"<strong></strong>"'));
    463497                $this->assertEquals('&#8216;<strong>Quoted Text</strong>&#8217;,', wptexturize("'<strong>Quoted Text</strong>',"));
    464498                $this->assertEquals('&#8220;<strong>Quoted Text</strong>&#8221;,', wptexturize('"<strong>Quoted Text</strong>",'));
    465499        }
    466        
     500
     501        //WP Ticket #15241
     502        function test_many_single_quotes() {
     503                $this->assertEquals('This isn&#8217;t inherently bad, but I don&#8217;t think it&#8217;s normal.', wptexturize("This isn't inherently bad, but I don't think it's normal."));
     504        }
     505
     506        //WP Ticket #1258
     507        function test_enumeration() {
     508                $this->assertEquals("&#8216;products&#8217;, &#8216;services&#8217;", wptexturize("'products', 'services'"));
     509                $this->assertEquals("&#8216;hello&#8217;, &#8216;world&#8217;, &#8217;tis", wptexturize("'hello', 'world', 'tis"));
     510                $this->assertEquals("&#8216;hello&#8217;, &#8216;world&#8217;, &#8217;tis ", wptexturize("'hello', 'world', 'tis "));
     511        }
     512
     513        //WP Ticket #11275
     514        function test_quoting() {
     515                $this->assertEquals('She said—&#8220;No!&#8221;', wptexturize('She said—"No!"'));
     516                $this->assertEquals('She said — &#8220;No!&#8221;', wptexturize('She said — "No!"'));
     517                $this->assertEquals('She said—&#8220;<a href="#">No!</a>&#8221;', wptexturize('She said—"<a href="#">No!</a>"'));
     518                $this->assertEquals('She said—&#8220;<a href="#">It&#8217;s Peter&#8217;s!</a>&#8221;', wptexturize('She said—"<a href="#">It\'s Peter\'s!</a>"'));
     519                $this->assertEquals('She said—&#8220;<a href="#">It&#8217;s Peter&#8217;s!</a>&#8221;', wptexturize('She said—"<a href="#">It\'s Peter\'s!</a>"'));
     520        }
     521
     522        //WP Ticket #15444
     523        function test_tag_followed_by_quote() {
     524                $this->knownWPBug(15444);
     525                $this->assertEquals('<a href="#">Jim</a>&#8217;s red bike.', wptexturize('<a href="#">Jim</a>\'s red bike.'));
     526                $this->assertEquals('&#8216;<a href="#">Jim</a>&#8217;s red bike.&#8217;', wptexturize('\'<a href="#">Jim</a>\'s red bike.\''));
     527                $this->assertEquals('&#8220;<a href="#">Jim</a>&#8217;s red bike.&#8221;', wptexturize('"<a href="#">Jim</a>\'s red bike."'));
     528                $this->assertEquals('<a href="#">Jim</a>&#8217;s &#8216;red bike.&#8217;', wptexturize('<a href="#">Jim</a>\'s \'red bike.\''));
     529                $this->assertEquals('<a href="#">Jim</a>&#8217;s &#8220;red bike.&#8221;', wptexturize('<a href="#">Jim</a>\'s "red bike."'));
     530                $this->assertEquals('<a href="#">Jim</a>&#8217;s &#8216;<a href="#">red bike</a>.&#8217;', wptexturize('<a href="#">Jim</a>\'s \'<a href="#">red bike</a>.\''));
     531                $this->assertEquals('<a href="#">Jim</a>&#8217;s &#8220;<a href="#">red bike</a>.&#8221;', wptexturize('<a href="#">Jim</a>\'s "<a href="#">red bike</a>."'));
     532        }
     533
    467534        function test_x() {
    468535                $this->assertEquals('14&#215;24', wptexturize("14x24"));
     536                $this->assertEquals('&#8216;14&#215;24&#8217;', wptexturize("'14x24'"));
     537                $this->assertEquals('&#8220;14&#215;24&#8221;', wptexturize('"14x24"'));
     538                $this->assertEquals('&#8216;<a href="#">14&#215;24</a>&#8217;', wptexturize('\'<a href="#">14x24</a>\''));
     539                $this->assertEquals('&#8220;<a href="#">14&#215;24</a>&#8221;', wptexturize('"<a href="#">14x24</a>"'));
    469540        }
    470541       
    471542        function test_minutes_seconds() {