CJavaScript::encode breaks emoji
lmcsu opened this issue ยท 5 comments
lmcsu commented
What steps will reproduce the problem?
Encode any emoji via CJavaScript::encode
What is the expected result?
Not a broken emoji
What do you get instead?
A broken emoji
Additional info
It's because of the old version of "zend-escaper".
Code from the new version solves the problem.
protected function jsMatcher($matches)
{
$chr = $matches[0];
if (strlen($chr) == 1) {
return sprintf('\\x%02X', ord($chr));
}
$chr = $this->convertEncoding($chr, 'UTF-16BE', 'UTF-8');
// old version (currently in Yii 1.1.22)
// return sprintf('\\u%04s', strtoupper(bin2hex($chr)));
// new code taken from
// https://github.com/laminas/laminas-escaper
$hex = strtoupper(bin2hex($chr));
if (strlen($hex) <= 4) {
return sprintf('\\u%04s', $hex);
}
$highSurrogate = substr($hex, 0, 4);
$lowSurrogate = substr($hex, 4, 4);
return sprintf('\\u%04s\\u%04s', $highSurrogate, $lowSurrogate);
}
Q | A |
---|---|
Yii version | 1.1.22 |
PHP version | 7.4 |
Operating system | Windows 10 |
samdark commented
I consider it a forward compatibility issue. Do you have time for a pull request?
lmcsu commented
Sorry, but I've never made any pull request before and I at first I need to learn more about how Git works. All I can do is to post issues like this one ๐๐
samdark commented
No worries. Will apply it then closer to next release.
marcovtwout commented
I created a PR for this issue for the above implementation (no test added or changelog modified yet)
marcovtwout commented
Fixed with #4325