Correctly mask non-BMP clipboard characters
JavaScript strings use UTF-16 encoding under the hood, but we only want a single '?' per character we replace. So we need to be more careful which methods we use when iterating over the clipboard string.
This commit is contained in:
parent
6b555f1f74
commit
6eb17b27a0
19
core/rfb.js
19
core/rfb.js
|
@ -490,16 +490,27 @@ export default class RFB extends EventTargetMixin {
|
||||||
this._clipboardText = text;
|
this._clipboardText = text;
|
||||||
RFB.messages.extendedClipboardNotify(this._sock, [extendedClipboardFormatText]);
|
RFB.messages.extendedClipboardNotify(this._sock, [extendedClipboardFormatText]);
|
||||||
} else {
|
} else {
|
||||||
let data = new Uint8Array(text.length);
|
let length, i;
|
||||||
for (let i = 0; i < text.length; i++) {
|
let data;
|
||||||
let code = text.charCodeAt(i);
|
|
||||||
|
length = 0;
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
|
for (let codePoint of text) {
|
||||||
|
length++;
|
||||||
|
}
|
||||||
|
|
||||||
|
data = new Uint8Array(length);
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
for (let codePoint of text) {
|
||||||
|
let code = codePoint.codePointAt(0);
|
||||||
|
|
||||||
/* Only ISO 8859-1 is supported */
|
/* Only ISO 8859-1 is supported */
|
||||||
if (code > 0xff) {
|
if (code > 0xff) {
|
||||||
code = 0x3f; // '?'
|
code = 0x3f; // '?'
|
||||||
}
|
}
|
||||||
|
|
||||||
data[i] = code;
|
data[i++] = code;
|
||||||
}
|
}
|
||||||
|
|
||||||
RFB.messages.clientCutText(this._sock, data);
|
RFB.messages.clientCutText(this._sock, data);
|
||||||
|
|
|
@ -441,6 +441,14 @@ describe('Remote Frame Buffer Protocol Client', function () {
|
||||||
new Uint8Array([97, 98, 99, 63]));
|
new Uint8Array([97, 98, 99, 63]));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should mask characters, not UTF-16 code points', function () {
|
||||||
|
client.clipboardPasteFrom('😂');
|
||||||
|
|
||||||
|
expect(RFB.messages.clientCutText).to.have.been.calledOnce;
|
||||||
|
expect(RFB.messages.clientCutText).to.have.been.calledWith(client._sock,
|
||||||
|
new Uint8Array([63]));
|
||||||
|
});
|
||||||
|
|
||||||
it('should send an notify if extended clipboard is supported by server', function () {
|
it('should send an notify if extended clipboard is supported by server', function () {
|
||||||
// Send our capabilities
|
// Send our capabilities
|
||||||
let data = [3, 0, 0, 0];
|
let data = [3, 0, 0, 0];
|
||||||
|
|
Loading…
Reference in New Issue