mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-30 12:06:56 +00:00
Merge branch '1.x' into 2.x
* 1.x: Explicitly specify the encoding for mb_ord in JS escaper
This commit is contained in:
@@ -282,7 +282,7 @@ function twig_escape_filter(Environment $env, $string, $strategy = 'html', $char
|
||||
return $shortMap[$char];
|
||||
}
|
||||
|
||||
$codepoint = mb_ord($char);
|
||||
$codepoint = mb_ord($char, 'UTF-8');
|
||||
if (0x10000 > $codepoint) {
|
||||
return sprintf('\u%04X', $codepoint);
|
||||
}
|
||||
|
||||
@@ -182,6 +182,22 @@ class Twig_Tests_Extension_EscaperTest extends 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()
|
||||
{
|
||||
$twig = new Environment($this->createMock(LoaderInterface::class));
|
||||
|
||||
Reference in New Issue
Block a user