From 9600c07a807453261fc57146a458b4f348ccb314 Mon Sep 17 00:00:00 2001 From: David Manthey Date: Fri, 27 Sep 2024 12:33:50 -0400 Subject: [PATCH] fix: Improve encoding html for screenshots If the html contains utf-16 surrogate pairs, the encoding would not be valid. --- src/util/common.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/util/common.js b/src/util/common.js index bf316b6726..a3702c1a1e 100644 --- a/src/util/common.js +++ b/src/util/common.js @@ -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) + ';'; }); },