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

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

     
    3131        static $static_setup = false, $opening_quote, $closing_quote, $default_no_texturize_tags, $default_no_texturize_shortcodes, $static_characters, $static_replacements, $dynamic_characters, $dynamic_replacements; 
    3232        $output = ''; 
    3333        $curl = ''; 
    34         $textarr = preg_split('/(<.*>|\[.*\])/Us', $text, -1, PREG_SPLIT_DELIM_CAPTURE); 
     34        $textarr = preg_split('/(<!--.*-->|<.*>|\[.*\])/Us', $text, -1, PREG_SPLIT_DELIM_CAPTURE); 
    3535        $stop = count($textarr); 
    3636 
    3737        // No need to set up these variables more than once 
     
    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                        '/([\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                        } 
     105                         
    81106                        // regular expressions 
    82107                        $curl = preg_replace($dynamic_characters, $dynamic_replacements, $curl); 
     108 
     109                        // Quotes that span across multiple tags & shortcodes 
     110                        // Dynamic regexps above ensure that there is at most 1 quote left in the string. 
     111                        // Otherwise, the less efficient preg_replace() within a while loop would be required. 
     112                        if ( strpos( $curl, '\'' ) !== false ) { 
     113                                $curl = str_replace( '\'', $single_quote_state, $curl); 
     114                                $single_quote_state = ( ( '&#8216;' == $single_quote_state ) ? '&#8217;' : '&#8216;' ); 
     115                        } 
     116                        if ( strpos($curl, '"' ) !== false ) { 
     117                                $curl = str_replace( '"', $double_quote_state, $curl); 
     118                                $double_quote_state = ( $opening_quote == $double_quote_state ) ? $closing_quote : $opening_quote; 
     119                        } 
     120                        // stats for quotes after tags above 
     121                        $text_node_count++; 
     122                        $whitespace_before_last_tag = ( preg_match('/\s$/', $curl) > 0 ); 
    83123                } elseif (!empty($curl)) { 
    84124                        /* 
    85125                         * Only call _wptexturize_pushpop_element if first char is correct 
  • wp-testcase/test_includes_formatting.php

     
    371371                 
    372372                $invalid_nest = '<pre></code>"baba"</pre>'; 
    373373                $this->assertEquals($invalid_nest, wptexturize($invalid_nest)); 
     374        } 
    374375 
     376        //WP Ticket #8912, #10033 
     377        function test_skip_html_comments() { 
     378                $this->assertEquals('<ul><li>Hello.</li><!--<li>Goodbye.</li>--></ul>', wptexturize('<ul><li>Hello.</li><!--<li>Goodbye.</li>--></ul>')); 
     379 
     380                $html = '<!--[if !IE]>-->' . "\n"; 
     381                $html .= '<object type="application/x-shockwave-flash" data="http://www.youtube.com/v/_nkZ3eHeXlc" width="320" height="260">' . "\n"; 
     382                $html .= '<!--<![endif]-->' . "\n"; 
     383                $this->assertEquals($html, wptexturize($html)); 
     384 
     385                $html = '<!--[if !IE]>-->' . "\n"; 
     386                $html .= '</object>' . "\n"; 
     387                $html .= '<!--<![endif]-->' . "\n"; 
     388                $this->assertEquals($html, wptexturize($html)); 
    375389        } 
    376          
     390 
    377391        //WP Ticket #1418 
    378392        function test_bracketed_quotes_1418() { 
    379393                $this->assertEquals('(&#8220;test&#8221;)', wptexturize('("test")')); 
     
    385399        function test_bracketed_quotes_3810() { 
    386400                $this->assertEquals('A dog (&#8220;Hubertus&#8221;) was sent out.', wptexturize('A dog ("Hubertus") was sent out.')); 
    387401        } 
    388          
     402 
    389403        //WP Ticket #4539 
    390404        function test_basic_quotes() { 
     405                $this->assertNotEquals('&#8216;&#8217;', wptexturize("''")); // this does not work as expected due to a static replacement 
     406                $this->assertEquals('&#8220;&#8221;', wptexturize('""')); 
     407                $this->assertEquals('&#8220;&#8221;', wptexturize("``''")); // this is what causes '' to fail 
     408                $this->assertEquals('&#8216; &#8217;', wptexturize("' '")); 
     409                $this->assertEquals('&#8220; &#8221;', wptexturize('" "')); 
     410                $this->assertEquals('&#8216;<img src="">&#8217;', wptexturize('\'<img src="">\'')); 
     411                $this->assertEquals('&#8220;<img src="">&#8221;', wptexturize('"<img src="">"')); 
     412                $this->assertEquals('Peter&#8217;s photo: &#8216;<img src="">&#8217;', wptexturize('Peter\'s photo: \'<img src="">\'')); 
     413                $this->assertEquals('Peter&#8217;s photo: &#8220;<img src="">&#8221;', wptexturize('Peter\'s photo: "<img src="">"')); 
     414 
    391415                $this->assertEquals('test&#8217;s', wptexturize('test\'s')); 
    392416                $this->assertEquals('test&#8217;s', wptexturize('test\'s')); 
    393417 
    394418                $this->assertEquals('&#8216;quoted&#8217;', wptexturize('\'quoted\'')); 
    395419                $this->assertEquals('&#8220;quoted&#8221;', wptexturize('"quoted"')); 
     420                $this->assertEquals('&#8216;quoted&#8217;s&#8217;', wptexturize('\'quoted\'s\'')); 
     421                $this->assertEquals('&#8220;quoted&#8217;s&#8221;', wptexturize('"quoted\'s"')); 
    396422 
    397423                $this->assertEquals('(&#8216;quoted&#8217;)', wptexturize('(\'quoted\')')); 
    398424                $this->assertEquals('{&#8220;quoted&#8221;}', wptexturize('{"quoted"}')); 
     425                $this->assertEquals('["quoted"]', wptexturize('["quoted"]')); // shortcode 
     426                $this->assertEquals('<"quoted">', wptexturize('<"quoted">')); // tag 
     427                $this->assertEquals('(&#8216;quoted&#8217;s&#8217;)', wptexturize('(\'quoted\'s\')')); 
     428                $this->assertEquals('{&#8220;quoted&#8217;s&#8221;}', wptexturize('{"quoted\'s"}')); 
     429                $this->assertEquals('["quoted\'s"]', wptexturize('["quoted\'s"]')); // shortcode 
     430                $this->assertEquals('<"quoted\'s">', wptexturize('<"quoted\'s">')); // tag 
    399431 
    400432                $this->assertEquals('&#8216;qu(ot)ed&#8217;', wptexturize('\'qu(ot)ed\'')); 
    401433                $this->assertEquals('&#8220;qu{ot}ed&#8221;', wptexturize('"qu{ot}ed"')); 
     434                $this->assertEquals('&#8220;qu[ot]ed&#8221;', wptexturize('"qu[ot]ed"')); 
     435                $this->assertEquals('&#8220;qu<ot>ed&#8221;', wptexturize('"qu<ot>ed"')); 
     436                $this->assertEquals('&#8216;qu(ot)ed&#8217;s&#8217;', wptexturize('\'qu(ot)ed\'s\'')); 
     437                $this->assertEquals('&#8220;qu{ot}ed&#8217;s&#8221;', wptexturize('"qu{ot}ed\'s"')); 
     438                $this->assertEquals('&#8220;qu[ot]ed&#8217;s&#8221;', wptexturize('"qu[ot]ed\'s"')); 
     439                $this->assertEquals('&#8220;qu<ot>ed&#8217;s&#8221;', wptexturize('"qu<ot>ed\'s"')); 
     440                $this->assertEquals('&#8216;qu(ot)&#8217;s&#8217;', wptexturize('\'qu(ot)\'s\'')); 
     441                $this->assertEquals('&#8220;qu{ot}&#8217;s&#8221;', wptexturize('"qu{ot}\'s"')); 
     442                $this->assertEquals('&#8220;qu[ot]&#8217;s&#8221;', wptexturize('"qu[ot]\'s"')); 
     443                $this->assertEquals('&#8220;qu<ot>&#8217;s&#8221;', wptexturize('"qu<ot>\'s"')); 
    402444 
    403445                $this->assertEquals('&#8216;test&#8217;s quoted&#8217;', wptexturize('\'test\'s quoted\'')); 
    404446                $this->assertEquals('&#8220;test&#8217;s quoted&#8221;', wptexturize('"test\'s quoted"')); 
    405447        } 
    406448 
     449        //WP Ticket #4539 
     450        function test_nested_quotes() { 
     451                $this->assertEquals('&#8220;This is a &#8216;nested quote&#8217;.&#8221;', wptexturize('"This is a \'nested quote\'."')); 
     452                $this->assertEquals('&#8216;This is a &#8220;nested quote&#8221;.&#8217;', wptexturize('\'This is a "nested quote".\'')); 
     453                $this->assertEquals('&#8220;These are some &#8216;nested&#8217; &#8216;quotes&#8217;.&#8221;', wptexturize('"These are some \'nested\' \'quotes\'."')); 
     454                $this->assertEquals('&#8216;These are some &#8220;nested&#8221; &#8220;quotes&#8221;.&#8217;', wptexturize('\'These are some "nested" "quotes".\'')); 
     455        } 
     456 
    407457        //WP Tickets #4539, #15241 
    408458        function test_full_sentences_with_unmatched_single_quotes() { 
    409459                $this->assertEquals( 
    410460                        'That means every moment you&#8217;re working on something without it being in the public it&#8217;s actually dying.', 
    411461                        wptexturize("That means every moment you're working on something without it being in the public it's actually dying.") 
    412462                ); 
     463                $this->assertEquals( 
     464                        '&#8216;That means every moment you&#8217;re working on something without it being in the public it&#8217;s actually dying.&#8217;', 
     465                        wptexturize("'That means every moment you're working on something without it being in the public it's actually dying.'") 
     466                ); 
     467                $this->assertEquals( 
     468                        '&#8220;That means every moment you&#8217;re working on something without it being in the public it&#8217;s actually dying.&#8221;', 
     469                        wptexturize("\"That means every moment you're working on something without it being in the public it's actually dying.\"") 
     470                ); 
     471                $this->assertEquals( 
     472                        'That means every moment you&#8217;re working on &#8216;something&#8217; without it being in the public it&#8217;s actually dying.', 
     473                        wptexturize("That means every moment you're working on 'something' without it being in the public it's actually dying.") 
     474                ); 
     475                $this->assertEquals( 
     476                        'That means every moment you&#8217;re working on &#8220;something&#8221; without it being in the public it&#8217;s actually dying.', 
     477                        wptexturize("That means every moment you're working on \"something\" without it being in the public it's actually dying.") 
     478                ); 
    413479        } 
    414480 
    415         //WP Ticket #4539 
     481        //WP Tickets #4539, #10606 
    416482        function test_quotes() { 
    417483                $this->knownWPBug(4539); 
    418484                $this->assertEquals('&#8220;Quoted String&#8221;', wptexturize('"Quoted String"')); 
    419485                $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>"')); 
     486                $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> "')); 
     487                $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>"')); 
    420488                $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>".')); 
    421489                $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.')); 
    422490                $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"')); 
     
    424492                $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.')); 
    425493                $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.')); 
    426494                $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.')); 
     495                $this->assertEquals('Here is &#8220;<a href="http://example.com">a test</a> with a link&#8221;.', wptexturize('Here is "<a href="http://example.com">a test</a> with a link".')); 
    427496                $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>".')); 
    428                 $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.')); 
     497                $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>" .')); 
     498                $this->assertEquals('Here is &#8220;<a href="http://example.com">a test with a link</a>&#8221;and a word stuck to the end.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>"and a word stuck to the end.')); 
    429499                $this->assertEquals('A test with a finishing number, &#8220;like 23&#8221;.', wptexturize('A test with a finishing number, "like 23".')); 
    430500                $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.')); 
    431501        } 
     
    451521                $this->assertEquals('&#8220;Class of 99&#8221;', wptexturize("\"Class of 99\"")); 
    452522                $this->assertEquals('&#8220;Class of &#8217;99&#8221;', wptexturize("\"Class of '99\"")); 
    453523        } 
    454          
    455         function test_quotes_after_numbers() { 
    456                 $this->assertEquals('Class of &#8217;99', wptexturize("Class of '99")); 
    457         } 
    458          
     524 
    459525        //WP Ticket #15241 
    460526        function test_other_html() { 
    461527                $this->knownWPBug(15241); 
    462528                $this->assertEquals('&#8216;<strong>', wptexturize("'<strong>")); 
     529                $this->assertEquals('&#8220;<strong>', wptexturize('"<strong>')); 
     530                $this->assertEquals('&#8216;<strong></strong>&#8217;', wptexturize("'<strong></strong>'")); 
     531                $this->assertEquals('&#8220;<strong></strong>&#8221;', wptexturize('"<strong></strong>"')); 
    463532                $this->assertEquals('&#8216;<strong>Quoted Text</strong>&#8217;,', wptexturize("'<strong>Quoted Text</strong>',")); 
    464533                $this->assertEquals('&#8220;<strong>Quoted Text</strong>&#8221;,', wptexturize('"<strong>Quoted Text</strong>",')); 
    465534        } 
    466          
     535 
     536        //WP Ticket #15241 
     537        function test_many_single_quotes() { 
     538                $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.")); 
     539        } 
     540 
     541        //WP Ticket #1258 
     542        function test_enumeration() { 
     543                $this->assertEquals("&#8216;products&#8217;, &#8216;services&#8217;", wptexturize("'products', 'services'")); 
     544                $this->assertEquals("&#8216;hello&#8217;, &#8216;world&#8217;, &#8217;tis", wptexturize("'hello', 'world', 'tis")); 
     545                $this->assertEquals("&#8216;hello&#8217;, &#8216;world&#8217;, &#8217;tis ", wptexturize("'hello', 'world', 'tis ")); 
     546        } 
     547 
     548        //WP Ticket #11275 
     549        function test_quoting() { 
     550                $this->assertEquals('She said—&#8220;No!&#8221;', wptexturize('She said—"No!"')); 
     551                $this->assertEquals('She said — &#8220;No!&#8221;', wptexturize('She said — "No!"')); 
     552                $this->assertEquals('She said—&#8220;<a href="#">No!</a>&#8221;', wptexturize('She said—"<a href="#">No!</a>"')); 
     553                $this->assertEquals('She said—&#8216;<a href="#">It&#8217;s Peter&#8217;s!</a>&#8217;', wptexturize('She said—\'<a href="#">It\'s Peter\'s!</a>\'')); 
     554                $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>"')); 
     555        } 
     556 
     557        //WP Ticket #15444 
     558        function test_tag_followed_by_quote() { 
     559                $this->knownWPBug(15444); 
     560                $this->assertEquals('<a href="#">Jim</a>&#8217;s red bike.', wptexturize('<a href="#">Jim</a>\'s red bike.')); 
     561                $this->assertEquals('&#8216;<a href="#">Jim</a>&#8217;s red bike.&#8217;', wptexturize('\'<a href="#">Jim</a>\'s red bike.\'')); 
     562                $this->assertEquals('&#8220;<a href="#">Jim</a>&#8217;s red bike.&#8221;', wptexturize('"<a href="#">Jim</a>\'s red bike."')); 
     563                $this->assertEquals('<a href="#">Jim</a>&#8217;s &#8216;red bike.&#8217;', wptexturize('<a href="#">Jim</a>\'s \'red bike.\'')); 
     564                $this->assertEquals('<a href="#">Jim</a>&#8217;s &#8220;red bike.&#8221;', wptexturize('<a href="#">Jim</a>\'s "red bike."')); 
     565                $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>.\'')); 
     566                $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>."')); 
     567        } 
     568 
    467569        function test_x() { 
    468570                $this->assertEquals('14&#215;24', wptexturize("14x24")); 
     571                $this->assertEquals('&#8216;14&#215;24&#8217;', wptexturize("'14x24'")); 
     572                $this->assertEquals('&#8220;14&#215;24&#8221;', wptexturize('"14x24"')); 
     573                $this->assertEquals('&#8216;<a href="#">14&#215;24</a>&#8217;', wptexturize('\'<a href="#">14x24</a>\'')); 
     574                $this->assertEquals('&#8220;<a href="#">14&#215;24</a>&#8221;', wptexturize('"<a href="#">14x24</a>"')); 
    469575        } 
    470          
     576 
     577        //WP Ticket #4116 
     578        function test_x_4116() { 
     579                $this->knownWPBug(4116); 
     580                $this->assertEquals('www.a4x3b.com', wptexturize("www.a4x3b.com")); 
     581                $this->assertEquals('http://www.youtube.com/watch?v=irWR7F0x2uU', wptexturize("http://www.youtube.com/watch?v=irWR7F0x2uU")); 
     582        } 
     583 
    471584        function test_minutes_seconds() { 
    472585                $this->assertEquals('9&#8242;', wptexturize('9\'')); 
    473586                $this->assertEquals('9&#8243;', wptexturize("9\"")); 
     
    484597                $this->assertEquals('&nbsp;&#8220;Testing&#8221;', wptexturize('&nbsp;"Testing"')); 
    485598                $this->assertEquals('&#38;&#8220;Testing&#8221;', wptexturize('&#38;"Testing"')); 
    486599        } 
     600 
     601        //WP Ticket #6969 
     602        function test_shortcode_skip() { 
     603                $this->assertEquals('[code lang="php"]$foo = \'bar\';[/code]', wptexturize('[code lang="php"]$foo = \'bar\';[/code]')); 
     604        } 
    487605} 
    488606 
    489607class TestCleanUrl extends WPTestCase {