From 10c0cc2e73ad22a6534d8c274f77048ebc41c275 Mon Sep 17 00:00:00 2001 From: NI Date: Sun, 15 Sep 2019 06:51:38 +0800 Subject: [PATCH] Convert Telnet output to the correct charset as well --- DEPENDENCIES.md | 1 + package-lock.json | 17 ++++++++++++++--- package.json | 1 + ui/commands/common.js | 3 --- ui/control/telnet.js | 10 +++++++--- 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/DEPENDENCIES.md b/DEPENDENCIES.md index 483d53b..bc4535d 100644 --- a/DEPENDENCIES.md +++ b/DEPENDENCIES.md @@ -15,6 +15,7 @@ Major dependencies includes: - [normalize.css](https://github.com/necolas/normalize.css), Licensed under MIT license - [Roboto font](https://en.wikipedia.org/wiki/Roboto), Licensed under Apache license. Packaged by [Christian Hoffmeister](https://github.com/choffmeister/roboto-fontface-bower), Licensed under Apache 2.0 +- [iconv-lite](https://github.com/ashtuchkin/iconv-lite), Licensed under MIT license ## For back-end application diff --git a/package-lock.json b/package-lock.json index b5e7ac6..63c10ee 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5023,6 +5023,17 @@ "chardet": "^0.7.0", "iconv-lite": "^0.4.24", "tmp": "^0.0.33" + }, + "dependencies": { + "iconv-lite": { + "version": "0.4.24", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", + "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", + "dev": true, + "requires": { + "safer-buffer": ">= 2.1.2 < 3" + } + } } }, "extglob": { @@ -6630,9 +6641,9 @@ "dev": true }, "iconv-lite": { - "version": "0.4.24", - "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", - "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.5.0.tgz", + "integrity": "sha512-NnEhI9hIEKHOzJ4f697DMz9IQEXr/MMJ5w64vN2/4Ai+wRnvV7SBrL0KLoRlwaKVghOc7LQ5YkPLuX146b6Ydw==", "dev": true, "requires": { "safer-buffer": ">= 2.1.2 < 3" diff --git a/package.json b/package.json index 5ef91ae..844658d 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "file-loader": "^4.2.0", "html-loader": "^0.5.5", "html-webpack-plugin": "^3.2.0", + "iconv-lite": "^0.5.0", "imagemin-webpack-plugin": "^2.4.2", "mini-css-extract-plugin": "^0.5.0", "mocha": "^6.2.0", diff --git a/ui/commands/common.js b/ui/commands/common.js index 3f7d715..b08067e 100644 --- a/ui/commands/common.js +++ b/ui/commands/common.js @@ -46,13 +46,10 @@ export const charsetPresets = [ "windows-1256", "windows-1257", "windows-1258", - "x-mac-cyrillic", "gbk", "gb18030", - "hz-gb-2312", "big5", "euc-jp", - "iso-2022-jp", "shift-jis", "euc-kr", "iso-2022-kr", diff --git a/ui/control/telnet.js b/ui/control/telnet.js index 5cf6887..092e7d7 100644 --- a/ui/control/telnet.js +++ b/ui/control/telnet.js @@ -15,6 +15,8 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . +import * as iconv from "iconv-lite"; + import * as subscribe from "../stream/subscribe.js"; import * as reader from "../stream/reader.js"; import * as color from "../commands/color.js"; @@ -331,12 +333,14 @@ class Control { this.colorM = color; this.colors = this.colorM.get(); - if (!data.charset || data.charset === "utf-8") { + this.charset = data.charset; + + if (this.charset === "utf-8") { this.charsetDecoder = d => { return d; }; } else { - let dec = new TextDecoder(data.charset), + let dec = new TextDecoder(this.charset), enc = new TextEncoder(); this.charsetDecoder = d => { @@ -449,7 +453,7 @@ class Control { } let currentLen = 0; - const enc = new TextEncoder("utf-8").encode(data); + const enc = new iconv.encode(data, this.charset); while (currentLen < enc.length) { const iacPos = this.searchNextIAC(currentLen, enc);