mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-17 04:46:49 +00:00
Replace implicit dependence on ext/iconv in JS escaper
polyfill-iconv does not support the UTF-16BE conversion
This commit is contained in:
@@ -282,15 +282,18 @@ function twig_escape_filter(Environment $env, $string, $strategy = 'html', $char
|
|||||||
return $shortMap[$char];
|
return $shortMap[$char];
|
||||||
}
|
}
|
||||||
|
|
||||||
// \uHHHH
|
$codepoint = mb_ord($char);
|
||||||
$char = twig_convert_encoding($char, 'UTF-16BE', 'UTF-8');
|
if (0x10000 > $codepoint) {
|
||||||
$char = strtoupper(bin2hex($char));
|
return sprintf('\u%04X', $codepoint);
|
||||||
|
|
||||||
if (4 >= \strlen($char)) {
|
|
||||||
return sprintf('\u%04s', $char);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
}, $string);
|
}, $string);
|
||||||
|
|
||||||
if ('UTF-8' !== $charset) {
|
if ('UTF-8' !== $charset) {
|
||||||
|
|||||||
Reference in New Issue
Block a user