From cbe3525f0472f8c976cf79a743ec87b9596695d3 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 62d709cb94..55cd094092 100644 --- a/guacamole-common-js/src/main/webapp/modules/Keyboard.js +++ b/guacamole-common-js/src/main/webapp/modules/Keyboard.js @@ -889,7 +889,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