Ticket #6583: bug6583.patch

File bug6583.patch, 2.2 KB (added by schiller, 4 years ago)

Patch against SVN

  • kses.php

     
    271271                'u' => array(), 
    272272                'ul' => array ( 
    273273                        'class' => array (), 
    274                         'style' => array (),  
     274                        'style' => array (), 
    275275                        'type' => array ()), 
    276276                'ol' => array ( 
    277277                        'class' => array (), 
    278278                        'start' => array (), 
    279                         'style' => array (),  
     279                        'style' => array (), 
    280280                        'type' => array ()), 
    281281                'var' => array ()); 
    282282        /** 
     
    896896 
    897897        $string = preg_replace('/&([A-Za-z][A-Za-z0-9]{0,19});/', '&\\1;', $string); 
    898898        $string = preg_replace_callback('/&#0*([0-9]{1,5});/', create_function('$matches', 'return wp_kses_normalize_entities2($matches[1]);'), $string); 
    899         $string = preg_replace('/&#([Xx])0*(([0-9A-Fa-f]{2}){1,2});/', '&#\\1\\2;', $string); 
     899        $string = preg_replace_callback('/&#([Xx])0*(([0-9A-Fa-f]{2}){1,2});/', create_function('$matches', 'return wp_kses_normalize_entities3($matches[2]);'), $string); 
    900900 
    901901        return $string; 
    902902} 
     
    913913 * @return string Correctly encoded entity 
    914914 */ 
    915915function wp_kses_normalize_entities2($i) { 
    916         return (($i > 65535) ? "&#$i;" : "&#$i;"); 
     916        return ( (!valid_unicode($i)) || ($i > 65535) ? "&#$i;" : "&#$i;"); 
    917917} 
    918918 
    919919/** 
     920 * wp_kses_normalize_entities3() - Callback for wp_kses_normalize_entities() for regular expression 
     921 * 
     922 * This function helps wp_kses_normalize_entities() to only accept valid Unicode numeric entities 
     923 * in hex form. 
     924 * 
     925 * @param string $h Hex string of encoded entity 
     926 * @return string Correctly encoded entity 
     927 */ 
     928function wp_kses_normalize_entities3($hexchars) { 
     929        return ( (!valid_unicode(hexdec($hexchars))) ? "&#x$hexchars;" : "&#x$hexchars;"); 
     930} 
     931 
     932/** 
     933 * valid_unicode() - Helper function to determine if a Unicode value is valid. 
     934 * 
     935 * @param int $i Unicode value 
     936 * @return bool true if the value was a valid Unicode number 
     937 */ 
     938function valid_unicode($i) { 
     939        return ( $i == 0x9 || $i == 0xa || $i == 0xd || 
     940                        ($i >= 0x20 && $i <= 0xd7ff) || 
     941                        ($i >= 0xe000 && $i <= 0xfffd) || 
     942                        ($i >= 0x10000 && $i <= 0x10ffff) ); 
     943} 
     944 
     945/** 
    920946 * wp_kses_decode_entities() - Convert all entities to their character counterparts. 
    921947 * 
    922948 * This function decodes numeric HTML entities (&#65; and &#x41;). It