From 2b9ec3cfec555ad49a253c031a4d0cd6c89c519d Mon Sep 17 00:00:00 2001 From: Scott Percival Date: Mon, 29 Jul 2024 15:48:17 +0800 Subject: [PATCH] GUACAMOLE-1972: Fix writing UTF-8 strings with surrogate pairs --- guacamole-common-js/src/main/webapp/modules/Keyboard.js | 7 ++++++- .../src/main/webapp/modules/StringWriter.js | 9 +++++++-- .../src/app/textInput/directives/guacTextInput.js | 9 +++++++-- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/guacamole-common-js/src/main/webapp/modules/Keyboard.js b/guacamole-common-js/src/main/webapp/modules/Keyboard.js index 748cab3cc9..603b2bb246 100644 --- a/guacamole-common-js/src/main/webapp/modules/Keyboard.js +++ b/guacamole-common-js/src/main/webapp/modules/Keyboard.js @@ -885,7 +885,12 @@ Guacamole.Keyboard = function Keyboard(element) { for (var i = 0; i < str.length; i++) { // Determine keysym of current character - var codepoint = str.codePointAt ? str.codePointAt(i) : str.charCodeAt(i); + var codepoint = str.codePointAt(i); + + // For surrogate pairs, skip the second 16 bits. + if (str.charCodeAt(i) != codepoint) { + i++; + } var keysym = keysym_from_charcode(codepoint); // Press and release key for current character diff --git a/guacamole-common-js/src/main/webapp/modules/StringWriter.js b/guacamole-common-js/src/main/webapp/modules/StringWriter.js index 6daeed229b..b295506b00 100644 --- a/guacamole-common-js/src/main/webapp/modules/StringWriter.js +++ b/guacamole-common-js/src/main/webapp/modules/StringWriter.js @@ -161,7 +161,12 @@ Guacamole.StringWriter = function(stream) { // Fill buffer with UTF-8 for (var i=0; i