Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GUACAMOLE-1972: Fix writing UTF-8 strings with surrogate pairs #999

Open
wants to merge 1 commit into
base: patch
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should remove the checks for codePointAt - it was only added in mid-2017.


// 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
Loading