Fix bug: Incorrect use of window.btoa and window.atob

Signed-off-by: Jianhui Zhao <jianhuizhao329@gmail.com>
This commit is contained in:
Jianhui Zhao
2018-01-22 15:50:15 +08:00
parent e0dcae2a63
commit 384c696105
2 changed files with 14 additions and 6 deletions
+13 -5
View File
@@ -72,6 +72,14 @@ export default {
},
methods: {
/* ucs-2 string to base64 encoded ascii */
utoa(str) {
return window.btoa(unescape(encodeURIComponent(str)));
},
/* base64 encoded ascii to ucs-2 string */
atou(str) {
return decodeURIComponent(escape(window.atob(str)));
},
beforeUpload (file) {
this.file = file;
return false;
@@ -87,7 +95,7 @@ export default {
for (var i = 0; i < len; i++) {
binary += String.fromCharCode(bytes[ i ]);
}
return window.btoa(binary);
return this.utoa(binary);
},
doUpload () {
this.modal_loading = true;
@@ -190,22 +198,22 @@ export default {
this.ws = ws;
this.sid = resp.sid;
term.on('data', (data)=> {
data = JSON.stringify({type: 'data', sid: this.sid, data: window.btoa(data)});
data = JSON.stringify({type: 'data', sid: this.sid, data: this.utoa(data)});
ws.send(data);
});
} else if (type == 'data') {
this.recvCnt++;
var data = window.atob(resp.data);
var data = this.atou(resp.data);
if (this.recvCnt < 4) {
if (data.match('login:') && this.username != '') {
data = JSON.stringify({type: 'data', sid: this.sid, data: window.btoa(this.username + '\n')});
data = JSON.stringify({type: 'data', sid: this.sid, data: this.utoa(this.username + '\n')});
ws.send(data);
return;
}
if (data.match('Password:') && this.password != '') {
data = JSON.stringify({type: 'data', sid: this.sid, data: window.btoa(this.password + '\n')});
data = JSON.stringify({type: 'data', sid: this.sid, data: this.utoa(this.password + '\n')});
ws.send(data);
return;
}
+1 -1
View File
File diff suppressed because one or more lines are too long