Fixed JS escaping for unicode characters with higher code points

This commit is contained in:
Mike Almond
2017-03-17 09:15:25 -04:00
committed by Fabien Potencier
parent c5ba65ca44
commit 7f9134952d
3 changed files with 15 additions and 2 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
* 1.32.1 (2017-XX-XX)
* n/a
* fixed JS escaping for unicode characters with higher code points
* 1.32.0 (2017-02-26)
+6 -1
View File
@@ -1168,8 +1168,13 @@ function _twig_escape_js_callback($matches)
// \uHHHH
$char = twig_convert_encoding($char, 'UTF-16BE', 'UTF-8');
$char = strtoupper(bin2hex($char));
return '\\u'.strtoupper(substr('0000'.bin2hex($char), -4));
if (4 >= strlen($char)) {
return sprintf('\u%04s', $char);
}
return sprintf('\u%04s\u%04s', substr($char, 0, -4), substr($char, -4));
}
function _twig_escape_css_callback($matches)
@@ -0,0 +1,8 @@
--TEST--
"escape" filter
--TEMPLATE--
{{ "é ♜ 𝌆"|e('js') }}
--DATA--
return array()
--EXPECT--
\u00E9\x20\u265C\x20\uD834\uDF06