Skip to content

Commit

Permalink
GUACAMOLE-1972: Fix writing UTF-8 strings with surrogate pairs
Browse files Browse the repository at this point in the history
  • Loading branch information
scottp-dpaw committed Jul 30, 2024
1 parent 6493a23 commit cbe3525
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
7 changes: 6 additions & 1 deletion guacamole-common-js/src/main/webapp/modules/Keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions guacamole-common-js/src/main/webapp/modules/StringWriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,12 @@ Guacamole.StringWriter = function(stream) {

// Fill buffer with UTF-8
for (var i=0; i<text.length; i++) {
var codepoint = text.charCodeAt(i);
var codepoint = text.codePointAt(i);

// For surrogate pairs, skip the second 16 bits.
if (text.charCodeAt(i) != codepoint) {
i++;
}
__append_utf8(codepoint);
}

Expand Down Expand Up @@ -202,4 +207,4 @@ Guacamole.StringWriter = function(stream) {
*/
this.onack = null;

};
};
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,14 @@ angular.module('textInput').directive('guacTextInput', [function guacTextInput()

// Send each codepoint within the string
for (var i=0; i<content.length; i++) {
var codepoint = content.charCodeAt(i);
var codepoint = content.codePointAt(i);

// For surrogate pairs, skip the second 16 bits.
if (content.charCodeAt(i) != codepoint) {
i++;
}
if (codepoint !== TEXT_INPUT_PADDING_CODEPOINT) {
sentText += String.fromCharCode(codepoint);
sentText += String.fromCodePoint(codepoint);
sendCodepoint(codepoint);
}
}
Expand Down

0 comments on commit cbe3525

Please sign in to comment.