From c92326cc257cf7c8b6c0ddc43ec81573c409bc64 Mon Sep 17 00:00:00 2001 From: Maximilian Krambach Date: Wed, 9 May 2018 19:40:57 +0200 Subject: js: more testing of nativeMessaging connection -- * There were some inconsistencies between utf-8, transfer and browsers' utf16, which broke characters that were split between individual messages. src/Connection now contains a workaround that reassembles javascripts' format from passed base64 strings. This needs someone more experienced looking. * Added several new tests which were failing during initial debugging of this issue * reorganized BrowsertestExtension to avoid cluttering. --- lang/js/src/Connection.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'lang/js/src') diff --git a/lang/js/src/Connection.js b/lang/js/src/Connection.js index 2c8792d6..64621f60 100644 --- a/lang/js/src/Connection.js +++ b/lang/js/src/Connection.js @@ -181,7 +181,8 @@ class Answer{ if (!this._response.hasOwnProperty(key)){ this._response[key] = ''; } - this._response[key] = this._response[key].concat(msg[key]); + // console.log(msg[key]); + this._response[key] += msg[key]; } //params should not change through the message else if (poa.params.indexOf(key) >= 0){ @@ -214,6 +215,22 @@ class Answer{ * TODO: does not care yet if completed. */ get message(){ + let keys = Object.keys(this._response); + let poa = permittedOperations[this.operation].answer; + for (let i=0; i < keys.length; i++) { + if (poa.data.indexOf(keys[i]) >= 0){ + if (this._response.base64 == true){ + let respatob = atob(this._response[keys[i]]); + + let result = decodeURIComponent( + respatob.split('').map(function(c) { + return '%' + + ('00' + c.charCodeAt(0).toString(16)).slice(-2); + }).join('')); + this._response[keys[i]] = result; + } + } + } return this._response; } } -- cgit v1.2.3