This commit is contained in:
Fabien Potencier
2020-09-14 15:17:28 +02:00
parent b22771177c
commit 67eea1843b
+10 -7
View File
@@ -1233,15 +1233,18 @@ function _twig_escape_js_callback($matches)
return $shortMap[$char];
}
// \uHHHH
$char = twig_convert_encoding($char, 'UTF-16BE', 'UTF-8');
$char = strtoupper(bin2hex($char));
if (4 >= \strlen($char)) {
return sprintf('\u%04s', $char);
$codepoint = mb_ord($char);
if (0x10000 > $codepoint) {
return sprintf('\u%04X', $codepoint);
}
return sprintf('\u%04s\u%04s', substr($char, 0, -4), substr($char, -4));
// Split characters outside the BMP into surrogate pairs
// https://tools.ietf.org/html/rfc2781.html#section-2.1
$u = $codepoint - 0x10000;
$high = 0xD800 | ($u >> 10);
$low = 0xDC00 | ($u & 0x3FF);
return sprintf('\u%04X\u%04X', $high, $low);
}
function _twig_escape_css_callback($matches)