Make WordPress Core

Ticket #17780: miqro-17780.patch

File miqro-17780.patch, 3.4 KB (added by miqrogroove, 11 years ago)
  • src/wp-includes/formatting.php

     
    665665                $quote_style = ENT_NOQUOTES;
    666666        }
    667667
    668         // Handle double encoding ourselves
    669         if ( $double_encode ) {
    670                 $string = @htmlspecialchars( $string, $quote_style, $charset );
    671         } else {
    672                 // Decode & into &
    673                 $string = wp_specialchars_decode( $string, $_quote_style );
     668        $string = @htmlspecialchars( $string, $quote_style, $charset, $double_encode );
    674669
    675                 // Guarantee every &entity; is valid or re-encode the &
    676                 $string = wp_kses_normalize_entities( $string );
    677 
    678                 // Now re-encode everything except &entity;
    679                 $string = preg_split( '/(&#?x?[0-9a-z]+;)/i', $string, -1, PREG_SPLIT_DELIM_CAPTURE );
    680 
    681                 for ( $i = 0, $c = count( $string ); $i < $c; $i += 2 ) {
    682                         $string[$i] = @htmlspecialchars( $string[$i], $quote_style, $charset );
    683                 }
    684                 $string = implode( '', $string );
    685         }
    686 
    687670        // Backwards compatibility
    688671        if ( 'single' === $_quote_style )
    689672                $string = str_replace( "'", '&#039;', $string );
  • tests/phpunit/tests/formatting/WPSpecialchars.php

     
    3939                $this->assertEquals( '&quot;&#039;hello!&#039;&quot;', _wp_specialchars($source, true) );
    4040                $this->assertEquals( $source, _wp_specialchars($source) );
    4141        }
     42
     43        /**
     44         * Check some of the double-encoding features for entity references.
     45         *
     46         * @ticket 17780
     47         * @dataProvider data_double_encoding
     48         */
     49        function test_double_encoding( $input, $output ) {
     50                return $this->assertEquals( $output, _wp_specialchars( $input, ENT_NOQUOTES, false, true ) );
     51        }
     52
     53        function data_double_encoding() {
     54                return array(
     55                        array(
     56                                'This & that, this &amp; that, &#8212; &quot; &QUOT; &Uacute; &nbsp; &#34; &#034; &#0034; &#x00022; &#x22; &dollar; &times;',
     57                                '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;',
     58                        ),
     59                        array(
     60                                '&& &&amp; &amp;&amp; &amp;;',
     61                                '&amp;&amp; &amp;&amp;amp; &amp;amp;&amp;amp; &amp;amp;;',
     62                        ),
     63                        array(
     64                                '&garbage; &***; &aaaa; &0000; &####; &;;',
     65                                '&amp;garbage; &amp;***; &amp;aaaa; &amp;0000; &amp;####; &amp;;;',
     66                        ),
     67                );
     68        }
     69
     70        /**
     71         * Check some of the double-encoding features for entity references.
     72         *
     73         * @ticket 17780
     74         * @dataProvider data_no_double_encoding
     75         */
     76        function test_no_double_encoding( $input, $output ) {
     77                return $this->assertEquals( $output, _wp_specialchars( $input, ENT_NOQUOTES, false, false ) );
     78        }
     79
     80        function data_no_double_encoding() {
     81                return array(
     82                        array(
     83                                'This & that, this &amp; that, &#8212; &quot; &QUOT; &Uacute; &nbsp; &#34; &#034; &#0034; &#x00022; &#x22; &dollar; &times;',
     84                                'This &amp; that, this &amp; that, &#8212; &quot; &amp;QUOT; &Uacute; &nbsp; &#34; &#034; &#0034; &#x00022; &#x22; &amp;dollar; &times;',
     85                        ),
     86                        array(
     87                                '&& &&amp; &amp;&amp; &amp;;',
     88                                '&amp;&amp; &amp;&amp; &amp;&amp; &amp;;',
     89                        ),
     90                        array(
     91                                '&garbage; &***; &aaaa; &0000; &####; &;;',
     92                                '&amp;garbage; &amp;***; &amp;aaaa; &amp;0000; &amp;####; &amp;;;',
     93                        ),
     94                );
     95        }
    4296}