Skip to content

Commit

Permalink
fix: Improve encoding html for screenshots
Browse files Browse the repository at this point in the history
If the html contains utf-16 surrogate pairs, the encoding would not be
valid.
  • Loading branch information
manthey committed Sep 27, 2024
1 parent 5a037e7 commit 9600c07
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/util/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -971,11 +971,22 @@ var util = {
* @memberof geo.util
*/
escapeUnicodeHTML: function (text) {
return text.replace(/./g, function (k) {
return text.replace(/[^- 0-9A-Za-z~`!@#$%^&*()_+={}|[\]\\:";'<>?,./]/g, function (k, pos) {
var code = k.charCodeAt(0);
if (code < 127) {
return k;
}
/* decode utf016 surrogate pairs */
if (code >= 0xD800 && code <= 0xE000) {
if (code < 0xDC00 || pos) {
return '';
}
var code0 = text.charCodeAt(pos - 1);
if (code0 < 0xD800 || code0 >= 0xDC00) {
return '';
}
code = (code0 - 0xD800) * 0x400 + (code - 0xDC00);
}
return '&#' + code.toString(10) + ';';
});
},
Expand Down

0 comments on commit 9600c07

Please sign in to comment.