WordPress.org

Make WordPress Core

Ticket #4539: some_more_progress.php.diff

File some_more_progress.php.diff, 3.7 KB (added by norbertm, 3 years ago)
  • wp-testcase/test_includes_formatting.php

     
    463463                $this->assertEquals('&#8216;<strong>Quoted Text</strong>&#8217;,', wptexturize("'<strong>Quoted Text</strong>',")); 
    464464                $this->assertEquals('&#8220;<strong>Quoted Text</strong>&#8221;,', wptexturize('"<strong>Quoted Text</strong>",')); 
    465465        } 
    466          
     466 
     467        //WP Ticket #15241 
     468        function test_many_single_quotes() { 
     469                $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.")); 
     470        } 
     471 
     472        //WP Ticket #1258 
     473        function test_enumeration() { 
     474                $this->assertEquals("&#8216;products&#8217;, &#8216;services&#8217;", wptexturize("'products', 'services'")); 
     475                $this->assertEquals("&#8216;hello&#8217;, &#8216;world&#8217;, &#8217;tis ", wptexturize("'hello', 'world', 'tis ")); 
     476        } 
     477 
     478        //WP Ticket #11275 
     479        function test_quoting() { 
     480                $this->assertEquals('She said—&#8220;No!&#8221;', wptexturize('She said—"No!"')); 
     481        } 
     482 
    467483        function test_x() { 
    468484                $this->assertEquals('14&#215;24', wptexturize("14x24")); 
    469485        } 
  • 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'); 
     59                $dynamic_map = array( 
     60                        '/\'(\d)/' => '&#8217;$1', // '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 
    7390        for ( $i = 0; $i < $stop; $i++ ) { 
    7491                $curl = $textarr[$i]; 
    7592 
     
    8097                        $curl = str_replace($static_characters, $static_replacements, $curl); 
    8198                        // regular expressions 
    8299                        $curl = preg_replace($dynamic_characters, $dynamic_replacements, $curl); 
     100                        // quotes that span multiple tags & shortcodes 
     101                        while (($pos = strpos($curl, '\'')) !== FALSE) { 
     102                                $curl = preg_replace('/\'/', $single_quote_state, $curl); 
     103                                $single_quote_state = (($single_quote_state == '&#8216;') ? '&#8217;' : '&#8216;'); 
     104                        } 
     105                        while (($pos = strpos($curl, '"')) !== FALSE) { 
     106                                $curl = preg_replace('/"/', $double_quote_state, $curl); 
     107                                $double_quote_state = (($double_quote_state == $opening_quote) ? $closing_quote : $opening_quote); 
     108                        } 
    83109                } elseif (!empty($curl)) { 
    84110                        /* 
    85111                         * Only call _wptexturize_pushpop_element if first char is correct