@@ -2904,23 +2904,49 @@ function urldecode_deep( $value ) {
29042904 * Converts email addresses characters to HTML entities to block spam bots.
29052905 *
29062906 * @since 0.71
2907+ * @since {WP_VERSION} Masquerades multi-byte characters.
29072908 *
29082909 * @param string $email_address Email address.
29092910 * @param int $hex_encoding Optional. Set to 1 to enable hex encoding.
29102911 * @return string Converted email address.
29112912 */
29122913function antispambot ( $ email_address , $ hex_encoding = 0 ) {
2914+ /*
2915+ * Email addresses passed into this function should not contain invalid UTF-8, but if they do,
2916+ * enforce the constraint by refusing to print any email address.
2917+ */
2918+ if ( ! wp_check_invalid_utf8 ( $ email_address ) ) {
2919+ return '' ;
2920+ }
2921+
29132922 $ email_no_spam_address = '' ;
29142923
2915- for ( $ i = 0 , $ len = strlen ( $ email_address ); $ i < $ len ; $ i ++ ) {
2916- $ j = rand ( 0 , 1 + $ hex_encoding );
2924+ $ at = 0 ;
2925+ $ next_at = 0 ;
2926+ $ end = strlen ( $ email_address );
2927+ $ invalid_length = 0 ;
2928+ while ( $ at < $ end ) {
2929+ if ( 0 === _wp_scan_utf8 ( $ email_address , $ next_at , $ invalid_length , null , 1 ) ) {
2930+ break ;
2931+ }
29172932
2918- if ( 0 === $ j ) {
2919- $ email_no_spam_address .= '&# ' . ord ( $ email_address [ $ i ] ) . '; ' ;
2920- } elseif ( 1 === $ j ) {
2921- $ email_no_spam_address .= $ email_address [ $ i ];
2922- } elseif ( 2 === $ j ) {
2923- $ email_no_spam_address .= '% ' . zeroise ( dechex ( ord ( $ email_address [ $ i ] ) ), 2 );
2933+ $ character = substr ( $ email_address , $ at , $ next_at - $ at );
2934+ switch ( rand ( 0 , 1 + $ hex_encoding ) ) {
2935+ case 0 :
2936+ $ code_point = mb_ord ( $ character );
2937+ $ email_no_spam_address .= "&# {$ code_point }; " ;
2938+ break ;
2939+
2940+ case 1 :
2941+ $ email_no_spam_address .= mb_ord ( $ character );
2942+ break ;
2943+
2944+ case 2 :
2945+ for ( $ i = 0 , $ byte_count = strlen ( $ character ); $ i < $ byte_count ; $ i ++ ) {
2946+ $ hex_value = bin2hex ( $ character );
2947+ $ email_no_spam_address .= "% {$ hex_value }" ;
2948+ }
2949+ break ;
29242950 }
29252951 }
29262952
0 commit comments