mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-01 04:57:23 +00:00
Explicitly specify the encoding for mb_ord in JS escaper
Explicitly specify the encoding for mb_ord in JS escaper - fix
This commit is contained in:
committed by
Fabien Potencier
parent
4fe3a98928
commit
da24c9340e
@@ -1237,7 +1237,7 @@ function _twig_escape_js_callback($matches)
|
||||
return $shortMap[$char];
|
||||
}
|
||||
|
||||
$codepoint = mb_ord($char);
|
||||
$codepoint = mb_ord($char, 'UTF-8');
|
||||
if (0x10000 > $codepoint) {
|
||||
return sprintf('\u%04X', $codepoint);
|
||||
}
|
||||
|
||||
@@ -177,6 +177,22 @@ class escapingTest extends \PHPUnit\Framework\TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function testJavascriptEscapingConvertsSpecialCharsWithInternalEncoding()
|
||||
{
|
||||
$twig = new Environment($this->createMock(LoaderInterface::class));
|
||||
$previousInternalEncoding = mb_internal_encoding();
|
||||
try {
|
||||
mb_internal_encoding('ISO-8859-1');
|
||||
foreach ($this->jsSpecialChars as $key => $value) {
|
||||
$this->assertEquals($value, twig_escape_filter($twig, $key, 'js'), 'Failed to escape: ' . $key);
|
||||
}
|
||||
} finally {
|
||||
if ($previousInternalEncoding !== false) {
|
||||
mb_internal_encoding($previousInternalEncoding);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function testJavascriptEscapingReturnsStringIfZeroLength()
|
||||
{
|
||||
$this->assertEquals('', twig_escape_filter($this->env, '', 'js'));
|
||||
|
||||
Reference in New Issue
Block a user