diff --git a/wp-includes/class-phpmailer.php b/wp-includes/class-phpmailer.php index 25e5570a3..a533d1093 100644 --- a/wp-includes/class-phpmailer.php +++ b/wp-includes/class-phpmailer.php @@ -1402,6 +1402,15 @@ class PHPMailer { return trim($output); } + /** + * Callback for converting to "=XX". + * @access private + * @return string + */ + function EncodeQ_callback ($matches) { + return "=".sprintf("%02X", ord($matches[1])); + } + /** * Encode string to q encoding. * @access private @@ -1413,15 +1422,18 @@ class PHPMailer { switch (strtolower($position)) { case 'phrase': - $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded); + $encoded = preg_replace_callback("/([^A-Za-z0-9!*+\/ -])/", + "EncodeQ_callback", $encoded); break; case 'comment': - $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded); + $encoded = preg_replace_callback("/([\(\)\"])/", + "EncodeQ_callback", $encoded); + break; case 'text': default: /* Replace every high ascii, control =, ? and _ characters */ - $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e', - "'='.sprintf('%02X', ord('\\1'))", $encoded); + $encoded = preg_replace_callback('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/', + "EncodeQ_callback", $encoded); break; } diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php index 153ef4e1f..145ee5ce2 100644 --- a/wp-includes/formatting.php +++ b/wp-includes/formatting.php @@ -772,6 +772,18 @@ function convert_chars($content, $deprecated = '') { return $content; } +/** + * Callback used to change %uXXXX to &#YYY; syntax + * + * @since 2.8? + * + * @param array $matches Single Match + * @return string An HTML entity + */ +function funky_javascript_callback($matches) { + return "&#".base_convert($matches[1],16,10).";"; +} + /** * Fixes javascript bugs in browsers. * @@ -788,9 +800,10 @@ function funky_javascript_fix($text) { // Fixes for browsers' javascript bugs global $is_macIE, $is_winIE; - /** @todo use preg_replace_callback() instead */ if ( $is_winIE || $is_macIE ) - $text = preg_replace("/\%u([0-9A-F]{4,4})/e", "'&#'.base_convert('\\1',16,10).';'", $text); + $text = preg_replace_callback("/\%u([0-9A-F]{4,4})/", + "funky_javascript_callback", + $text); return $text; }