diff --git a/ui/control/telnet.js b/ui/control/telnet.js index 30df246..56aa985 100644 --- a/ui/control/telnet.js +++ b/ui/control/telnet.js @@ -336,9 +336,15 @@ class Control { this.charset = data.charset; if (this.charset === "utf-8") { + let enc = new TextEncoder(); + this.charsetDecoder = d => { return d; }; + + this.charsetEncoder = dStr => { + return enc.encode(dStr); + }; } else { let dec = new TextDecoder(this.charset), enc = new TextEncoder(); @@ -350,6 +356,10 @@ class Control { }) ); }; + + this.charsetEncoder = dStr => { + return iconv.encode(dStr, this.charset); + }; } this.sender = data.send; @@ -453,13 +463,7 @@ class Control { } let currentLen = 0; - let enc = null; - - if (this.charset !== "utf-8") { - enc = new iconv.encode(data, this.charset); - } else { - enc = new TextEncoder().encode(data); - } + const enc = this.charsetEncoder(data); while (currentLen < enc.length) { const iacPos = this.searchNextIAC(currentLen, enc);