Make WordPress Core

Ticket #12284: 12284.patch

File 12284.patch, 6.8 KB (added by hakre, 14 years ago)

Fix (IF); Opt (Speed) and Imp (Coding Standards)

  • formatting.php

     
    334334        // Handle double encoding ourselves
    335335        if ( !$double_encode ) {
    336336                $string = wp_specialchars_decode( $string, $_quote_style );
     337
     338                /* Critical */
     339                // The previous line decodes &phrase; into &phrase;  We must guarantee that &phrase; is valid before proceeding.
     340                $string = wp_kses_normalize_entities( $string );
     341
     342                // Now proceed with custom double-encoding silliness
    337343                $string = preg_replace( '/&(#?x?[0-9a-z]+);/i', '|wp_entity|$1|/wp_entity|', $string );
    338344        }
    339345
  • kses.php

     
    336336}
    337337
    338338/**
     339 * Kses allowed HTML Entity Names.
     340 *
     341 * @see wp_kses_normalize_entities()
     342 * @see wp_kses_named_entities()
     343 *
     344 * @global array $allowedentitynames
     345 * @since 3.0.0
     346 */
     347$allowedentitynames = array(
     348        'nbsp',   'iexcl',  'cent',   'pound',  'curren', 'yen',
     349        'brvbar', 'sect',   'uml',    'copy',   'ordf',   'laquo',
     350        'not',    'shy',    'reg',        'macr',   'deg',    'plusmn',
     351        'acute',  'micro',  'para',   'middot', 'cedil',  'ordm',
     352        'raquo',  'iquest', 'Agrave', 'Aacute', 'Acirc',  'Atilde',
     353        'Auml',   'Aring',      'AElig',  'Ccedil', 'Egrave', 'Eacute',
     354        'Ecirc',  'Euml',   'Igrave', 'Iacute', 'Icirc',  'Iuml',
     355        'ETH',    'Ntilde', 'Ograve', 'Oacute', 'Ocirc',  'Otilde',
     356        'Ouml',   'times',  'Oslash', 'Ugrave', 'Uacute', 'Ucirc',
     357        'Uuml',   'Yacute', 'THORN',  'szlig',  'agrave', 'aacute',
     358        'acirc',  'atilde', 'auml',   'aring',  'aelig',  'ccedil',
     359        'egrave', 'eacute', 'ecirc',  'euml',   'igrave', 'iacute',
     360        'icirc',  'iuml',   'eth',    'ntilde', 'ograve', 'oacute',
     361        'ocirc',  'otilde', 'ouml',   'divide', 'oslash', 'ugrave',
     362        'uacute', 'ucirc',  'uuml',   'yacute', 'thorn',  'yuml',
     363        'quot',   'amp',    'lt',     'gt',     'apos',   'OElig',
     364        'oelig',  'Scaron', 'scaron', 'Yuml',   'circ',   'tilde',
     365        'ensp',   'emsp',   'thinsp', 'zwnj',   'zwj',    'lrm',
     366        'rlm',    'ndash',  'mdash',  'lsquo',  'rsquo',  'sbquo',
     367        'ldquo',  'rdquo',  'bdquo',  'dagger', 'Dagger', 'permil',
     368        'lsaquo', 'rsaquo', 'euro',   'fnof',   'Alpha',  'Beta',
     369        'Gamma',  'Delta',  'Epsilon','Zeta',   'Eta',    'Theta',
     370        'Iota',   'Kappa',  'Lambda', 'Mu',     'Nu',     'Xi',
     371        'Omicron','Pi',     'Rho',    'Sigma',  'Tau',    'Upsilon',
     372        'Phi',    'Chi',    'Psi',    'Omega',  'alpha',  'beta',
     373        'gamma',  'delta',  'epsilon','zeta',   'eta',    'theta',
     374        'iota',   'kappa',  'lambda', 'mu',     'nu',     'xi',
     375        'omicron','pi',     'rho',    'sigmaf', 'sigma',  'tau',
     376        'upsilon','phi',    'chi',    'psi',    'omega',  'thetasym',
     377        'upsih',  'piv',    'bull',   'hellip', 'prime',  'Prime',
     378        'oline',  'frasl',  'weierp', 'image',  'real',   'trade',
     379        'alefsym','larr',   'uarr',   'rarr',   'darr',   'harr',
     380        'crarr',  'lArr',   'uArr',   'rArr',   'dArr',   'hArr',
     381        'forall', 'part',   'exist',  'empty',  'nabla',  'isin',
     382        'notin',  'ni',     'prod',   'sum',    'minus',  'lowast',
     383        'radic',  'prop',   'infin',  'ang',    'and',    'or',
     384        'cap',    'cup',    'int',    'sim',    'cong',   'asymp',
     385        'ne',     'equiv',  'le',     'ge',     'sub',    'sup',
     386        'nsub',   'sube',   'supe',   'oplus',  'otimes', 'perp',
     387        'sdot',   'lceil',  'rceil',  'lfloor', 'rfloor', 'lang',
     388        'rang',   'loz',    'spades', 'clubs',  'hearts', 'diams'
     389);
     390
     391/**
    339392 * Filters content and keeps only allowable HTML elements.
    340393 *
    341394 * This function makes sure that only the allowed HTML element names, attribute
     
    945998 * @param string $string Content to normalize entities
    946999 * @return string Content with normalized entities
    9471000 */
    948 function wp_kses_normalize_entities($string) {
     1001function wp_kses_normalize_entities( $string ) {
    9491002        # Disarm all entities by converting & to &
    9501003
    9511004        $string = str_replace('&', '&', $string);
    9521005
    9531006        # Change back the allowed entities in our entity whitelist
    9541007
    955         $string = preg_replace('/&([A-Za-z][A-Za-z0-9]{0,19});/', '&\\1;', $string);
     1008        $string = preg_replace_callback('/&([A-Za-z]{2,8});/', 'wp_kses_named_entities', $string);
    9561009        $string = preg_replace_callback('/&#0*([0-9]{1,5});/', 'wp_kses_normalize_entities2', $string);
    9571010        $string = preg_replace_callback('/&#([Xx])0*(([0-9A-Fa-f]{2}){1,2});/', 'wp_kses_normalize_entities3', $string);
    9581011
     
    9621015/**
    9631016 * Callback for wp_kses_normalize_entities() regular expression.
    9641017 *
     1018 * This function only accepts valid named entity references, which are finite,
     1019 * case-sensitive, and highly scrutinized by HTML and XML validators.
     1020 *
     1021 * @access private
     1022 * @since 3.0.0
     1023 * @see wp_kses_normalize_entities()
     1024 * @uses $allowedentitynames
     1025 * @param array $matches preg_replace_callback() matches array
     1026 * @return string Correctly encoded entity
     1027 */
     1028function wp_kses_named_entities( $matches ) {
     1029        if ( empty($matches[1]) )
     1030                return '';
     1031
     1032        $i = $matches[1];
     1033        return ( in_array( $i, $GLOBALS['allowedentitynames'] ) ? "&$i;" : "&$i;"  );
     1034}
     1035
     1036/**
     1037 * Callback for wp_kses_normalize_entities() regular expression.
     1038 *
    9651039 * This function helps wp_kses_normalize_entities() to only accept 16 bit values
    9661040 * and nothing more for &#number; entities.
    9671041 *
    9681042 * @access private
    9691043 * @since 1.0.0
     1044 * @see wp_kses_normalize_entities()
    9701045 *
    9711046 * @param array $matches preg_replace_callback() matches array
    9721047 * @return string Correctly encoded entity
    9731048 */
    974 function wp_kses_normalize_entities2($matches) {
    975         if ( ! isset($matches[1]) || empty($matches[1]) )
     1049function wp_kses_normalize_entities2( $matches ) {
     1050        if ( empty( $matches[1] ) )
    9761051                return '';
    9771052
    9781053        $i = $matches[1];
    979         return ( ( ! valid_unicode($i) ) || ($i > 65535) ? "&#$i;" : "&#$i;" );
     1054        return ( valid_unicode( $i ) || ($i > 65535) ? "&#$i;" : "&#$i;" );
    9801055}
    9811056
    9821057/**
     
    9861061 * numeric entities in hex form.
    9871062 *
    9881063 * @access private
     1064 * @since {@internal Version Unknown}}
     1065 * @see wp_kses_normalize_entities()
    9891066 *
    9901067 * @param array $matches preg_replace_callback() matches array
    9911068 * @return string Correctly encoded entity
    9921069 */
    993 function wp_kses_normalize_entities3($matches) {
    994         if ( ! isset($matches[2]) || empty($matches[2]) )
     1070function wp_kses_normalize_entities3( $matches ) {
     1071        if ( empty( $matches[2] ) )
    9951072                return '';
    9961073
    9971074        $hexchars = $matches[2];
    998         return ( ( ! valid_unicode(hexdec($hexchars)) ) ? "&#x$hexchars;" : "&#x$hexchars;" );
     1075        return ( valid_unicode( hexdec( $hexchars ) ) ? "&#x$hexchars;" : "&#x$hexchars;" );
    9991076}
    10001077
    10011078/**
     
    10041081 * @param int $i Unicode value
    10051082 * @return bool true if the value was a valid Unicode number
    10061083 */
    1007 function valid_unicode($i) {
     1084function valid_unicode( $i ) {
    10081085        return ( $i == 0x9 || $i == 0xa || $i == 0xd ||
    10091086                        ($i >= 0x20 && $i <= 0xd7ff) ||
    10101087                        ($i >= 0xe000 && $i <= 0xfffd) ||