summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2022-10-27 16:29:38 +0200
committerPierre Ossman <ossman@cendio.se>2022-10-27 16:29:38 +0200
commit2d559fb2e11b37c413171698a4bc197504a328d0 (patch)
tree87c1da2d16eef1d5ea25668f8efc07af28c3ac1a
parentf59be0586f675394514003784b7ffffbb845cc2b (diff)
parent6eb17b27a0c86cc12321d7279eef45713b37aa2f (diff)
downloadnovnc-2d559fb2e11b37c413171698a4bc197504a328d0.tar.gz
Merge branch 'latin1' of https://github.com/CendioOssman/noVNC
-rw-r--r--core/rfb.js25
-rw-r--r--tests/assertions.js6
-rw-r--r--tests/test.rfb.js21
3 files changed, 40 insertions, 12 deletions
diff --git a/core/rfb.js b/core/rfb.js
index e6647ef..c96518d 100644
--- a/core/rfb.js
+++ b/core/rfb.js
@@ -490,10 +490,27 @@ export default class RFB extends EventTargetMixin {
this._clipboardText = text;
RFB.messages.extendedClipboardNotify(this._sock, [extendedClipboardFormatText]);
} else {
- let data = new Uint8Array(text.length);
- for (let i = 0; i < text.length; i++) {
- // FIXME: text can have values outside of Latin1/Uint8
- data[i] = text.charCodeAt(i);
+ let length, i;
+ let data;
+
+ 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 */
+ if (code > 0xff) {
+ code = 0x3f; // '?'
+ }
+
+ data[i++] = code;
}
RFB.messages.clientCutText(this._sock, data);
diff --git a/tests/assertions.js b/tests/assertions.js
index c33c81e..739f637 100644
--- a/tests/assertions.js
+++ b/tests/assertions.js
@@ -29,12 +29,6 @@ chai.use(function (_chai, utils) {
_chai.Assertion.addMethod('sent', function (targetData) {
const obj = this._obj;
- obj.inspect = () => {
- const res = { _websocket: obj._websocket, rQi: obj._rQi, _rQ: new Uint8Array(obj._rQ.buffer, 0, obj._rQlen),
- _sQ: new Uint8Array(obj._sQ.buffer, 0, obj._sQlen) };
- res.prototype = obj;
- return res;
- };
const data = obj._websocket._getSentData();
let same = true;
if (data.length != targetData.length) {
diff --git a/tests/test.rfb.js b/tests/test.rfb.js
index 75d1e11..ad00edf 100644
--- a/tests/test.rfb.js
+++ b/tests/test.rfb.js
@@ -111,11 +111,12 @@ describe('Remote Frame Buffer Protocol Client', function () {
};
// Avoiding printing the entire Websock buffer on errors
- Websock.prototype.toString = function () { return "[object Websock]"; };
+ Websock.prototype.inspect = function () { return "[object Websock]"; };
});
after(function () {
- delete Websock.prototype.toString;
+ Websock.prototype._allocateBuffers = Websock.prototype._oldAllocateBuffers;
+ delete Websock.prototype.inspect;
this.clock.restore();
window.requestAnimationFrame = raf;
window.ResizeObserver = realObserver;
@@ -432,6 +433,22 @@ describe('Remote Frame Buffer Protocol Client', function () {
new Uint8Array([97, 98, 99]));
});
+ it('should mask unsupported characters', function () {
+ client.clipboardPasteFrom('abc€');
+
+ expect(RFB.messages.clientCutText).to.have.been.calledOnce;
+ expect(RFB.messages.clientCutText).to.have.been.calledWith(client._sock,
+ 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 () {
// Send our capabilities
let data = [3, 0, 0, 0];