Make WordPress Core

Ticket #17780: miqro-17780.3.patch

File miqro-17780.3.patch, 3.9 KB (added by miqrogroove, 11 years ago)

Added test results in patched version.

  • src/wp-includes/formatting.php

     
    681681                $quote_style = ENT_NOQUOTES;
    682682        }
    683683
    684         // Handle double encoding ourselves
    685         if ( $double_encode ) {
    686                 $string = @htmlspecialchars( $string, $quote_style, $charset );
    687         } else {
    688                 // Decode & into &
    689                 $string = wp_specialchars_decode( $string, $_quote_style );
     684        $string = @htmlspecialchars( $string, $quote_style, $charset, $double_encode );
    690685
    691                 // Guarantee every &entity; is valid or re-encode the &
    692                 $string = wp_kses_normalize_entities( $string );
    693 
    694                 // Now re-encode everything except &entity;
    695                 $string = preg_split( '/(&#?x?[0-9a-z]+;)/i', $string, -1, PREG_SPLIT_DELIM_CAPTURE );
    696 
    697                 for ( $i = 0, $c = count( $string ); $i < $c; $i += 2 ) {
    698                         $string[$i] = @htmlspecialchars( $string[$i], $quote_style, $charset );
    699                 }
    700                 $string = implode( '', $string );
    701         }
    702 
    703686        // Backwards compatibility
    704687        if ( 'single' === $_quote_style )
    705688                $string = str_replace( "'", '&#039;', $string );
  • tests/phpunit/tests/formatting/WPSpecialchars.php

     
    1717
    1818                // Allowed entities should be unchanged
    1919                foreach ( $allowedentitynames as $ent ) {
     20                        if ( 'apos' == $ent ) {
     21                                // But for some reason, PHP doesn't allow &apos;
     22                                continue;
     23                        }
    2024                        $ent = '&' . $ent . ';';
    2125                        $this->assertEquals( $ent, _wp_specialchars( $ent ) );
    2226                }
     
    3943                $this->assertEquals( '&quot;&#039;hello!&#039;&quot;', _wp_specialchars($source, true) );
    4044                $this->assertEquals( $source, _wp_specialchars($source) );
    4145        }
     46
     47        /**
     48         * Check some of the double-encoding features for entity references.
     49         *
     50         * @ticket 17780
     51         * @dataProvider data_double_encoding
     52         */
     53        function test_double_encoding( $input, $output ) {
     54                return $this->assertEquals( $output, _wp_specialchars( $input, ENT_NOQUOTES, false, true ) );
     55        }
     56
     57        function data_double_encoding() {
     58                return array(
     59                        array(
     60                                'This & that, this &amp; that, &#8212; &quot; &QUOT; &Uacute; &nbsp; &#34; &#034; &#0034; &#x00022; &#x22; &dollar; &times;',
     61                                'This &amp; that, this &amp;amp; that, &amp;#8212; &amp;quot; &amp;QUOT; &amp;Uacute; &amp;nbsp; &amp;#34; &amp;#034; &amp;#0034; &amp;#x00022; &amp;#x22; &amp;dollar; &amp;times;',
     62                        ),
     63                        array(
     64                                '&& &&amp; &amp;&amp; &amp;;',
     65                                '&amp;&amp; &amp;&amp;amp; &amp;amp;&amp;amp; &amp;amp;;',
     66                        ),
     67                        array(
     68                                '&garbage; &***; &aaaa; &0000; &####; &;;',
     69                                '&amp;garbage; &amp;***; &amp;aaaa; &amp;0000; &amp;####; &amp;;;',
     70                        ),
     71                        array(
     72                                '&amp;amp; &amp;quot; &amp;#8212;',
     73                                '&amp;amp;amp; &amp;amp;quot; &amp;amp;#8212;',
     74                        ),
     75                );
     76        }
     77
     78        /**
     79         * Check some of the double-encoding features for entity references.
     80         *
     81         * @ticket 17780
     82         * @dataProvider data_no_double_encoding
     83         */
     84        function test_no_double_encoding( $input, $output ) {
     85                return $this->assertEquals( $output, _wp_specialchars( $input, ENT_NOQUOTES, false, false ) );
     86        }
     87
     88        function data_no_double_encoding() {
     89                return array(
     90                        array(
     91                                'This & that, this &amp; that, &#8212; &quot; &QUOT; &Uacute; &nbsp; &#34; &#034; &#0034; &#x00022; &#x22; &dollar; &times;',
     92                                'This &amp; that, this &amp; that, &#8212; &quot; &amp;QUOT; &Uacute; &nbsp; &#34; &#034; &#0034; &#x00022; &#x22; &amp;dollar; &times;',
     93                        ),
     94                        array(
     95                                '&& &&amp; &amp;&amp; &amp;;',
     96                                '&amp;&amp; &amp;&amp; &amp;&amp; &amp;;',
     97                        ),
     98                        array(
     99                                '&garbage; &***; &aaaa; &0000; &####; &;;',
     100                                '&amp;garbage; &amp;***; &amp;aaaa; &amp;0000; &amp;####; &amp;;;',
     101                        ),
     102                        array(
     103                                '&amp;amp; &amp;quot; &amp;#8212;',
     104                                '&amp;amp; &amp;quot; &amp;#8212;',
     105                        ),
     106                );
     107        }
    42108}