Ticket #12284: 12284.patch
File 12284.patch, 6.8 KB (added by , 14 years ago) |
---|
-
formatting.php
334 334 // Handle double encoding ourselves 335 335 if ( !$double_encode ) { 336 336 $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 337 343 $string = preg_replace( '/&(#?x?[0-9a-z]+);/i', '|wp_entity|$1|/wp_entity|', $string ); 338 344 } 339 345 -
kses.php
336 336 } 337 337 338 338 /** 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 /** 339 392 * Filters content and keeps only allowable HTML elements. 340 393 * 341 394 * This function makes sure that only the allowed HTML element names, attribute … … 945 998 * @param string $string Content to normalize entities 946 999 * @return string Content with normalized entities 947 1000 */ 948 function wp_kses_normalize_entities( $string) {1001 function wp_kses_normalize_entities( $string ) { 949 1002 # Disarm all entities by converting & to & 950 1003 951 1004 $string = str_replace('&', '&', $string); 952 1005 953 1006 # Change back the allowed entities in our entity whitelist 954 1007 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); 956 1009 $string = preg_replace_callback('/&#0*([0-9]{1,5});/', 'wp_kses_normalize_entities2', $string); 957 1010 $string = preg_replace_callback('/&#([Xx])0*(([0-9A-Fa-f]{2}){1,2});/', 'wp_kses_normalize_entities3', $string); 958 1011 … … 962 1015 /** 963 1016 * Callback for wp_kses_normalize_entities() regular expression. 964 1017 * 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 */ 1028 function 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 * 965 1039 * This function helps wp_kses_normalize_entities() to only accept 16 bit values 966 1040 * and nothing more for &#number; entities. 967 1041 * 968 1042 * @access private 969 1043 * @since 1.0.0 1044 * @see wp_kses_normalize_entities() 970 1045 * 971 1046 * @param array $matches preg_replace_callback() matches array 972 1047 * @return string Correctly encoded entity 973 1048 */ 974 function wp_kses_normalize_entities2( $matches) {975 if ( ! isset($matches[1]) || empty($matches[1]) )1049 function wp_kses_normalize_entities2( $matches ) { 1050 if ( empty( $matches[1] ) ) 976 1051 return ''; 977 1052 978 1053 $i = $matches[1]; 979 return ( ( ! valid_unicode($i) ) || ($i > 65535) ? "&#$i;" : "&#$i;" );1054 return ( valid_unicode( $i ) || ($i > 65535) ? "&#$i;" : "&#$i;" ); 980 1055 } 981 1056 982 1057 /** … … 986 1061 * numeric entities in hex form. 987 1062 * 988 1063 * @access private 1064 * @since {@internal Version Unknown}} 1065 * @see wp_kses_normalize_entities() 989 1066 * 990 1067 * @param array $matches preg_replace_callback() matches array 991 1068 * @return string Correctly encoded entity 992 1069 */ 993 function wp_kses_normalize_entities3( $matches) {994 if ( ! isset($matches[2]) || empty($matches[2]) )1070 function wp_kses_normalize_entities3( $matches ) { 1071 if ( empty( $matches[2] ) ) 995 1072 return ''; 996 1073 997 1074 $hexchars = $matches[2]; 998 return ( ( ! valid_unicode(hexdec($hexchars)) ) ? "&#x$hexchars;" : "&#x$hexchars;" );1075 return ( valid_unicode( hexdec( $hexchars ) ) ? "&#x$hexchars;" : "&#x$hexchars;" ); 999 1076 } 1000 1077 1001 1078 /** … … 1004 1081 * @param int $i Unicode value 1005 1082 * @return bool true if the value was a valid Unicode number 1006 1083 */ 1007 function valid_unicode( $i) {1084 function valid_unicode( $i ) { 1008 1085 return ( $i == 0x9 || $i == 0xa || $i == 0xd || 1009 1086 ($i >= 0x20 && $i <= 0xd7ff) || 1010 1087 ($i >= 0xe000 && $i <= 0xfffd) ||