diff options
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | lib/http_observer/process_response.js | 30 | ||||
-rw-r--r-- | lib/http_observer/stream_loader.js | 2 |
3 files changed, 20 insertions, 19 deletions
@@ -1,3 +1,10 @@ +2015-06-16 Nik Nyby <nikolas@gnu.org> + * Fixed a mangled Unicode character problem in + process_response.js. Thanks to Jookia for the patch. + + * onDetermineCharset now only checks for valid charsets. + Thanks to Ruben Rodriguez for the patch. + 2015-04-02 Nik Nyby <nikolas@gnu.org> * Remove the draggable complain banner functionality. * Add JsChecker.isFreeLicensed method from Ruben Rodriguez. We're diff --git a/lib/http_observer/process_response.js b/lib/http_observer/process_response.js index c1f5e88..000daa2 100644 --- a/lib/http_observer/process_response.js +++ b/lib/http_observer/process_response.js @@ -81,17 +81,6 @@ var processResponseObject = { }, /** - * genBinaryOutput - * Set or reset binaryOutputStream and storageStream. - */ - genBinaryOutput: function () { - this.storageStream = Cc["@mozilla.org/storagestream;1"] - .createInstance(Ci.nsIStorageStream); - this.binaryOutputStream = Cc["@mozilla.org/binaryoutputstream;1"] - .createInstance(Ci.nsIBinaryOutputStream); - }, - - /** * Gather the data gathered from onDataAvailable. */ setData: function () { @@ -393,21 +382,26 @@ var processResponseObject = { jsListenerCallback: function () { - var len = this.data.length; + var converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"] + .createInstance(Ci.nsIScriptableUnicodeConverter); - this.genBinaryOutput(); + if (typeof this.req.contentCharset !== 'undefined' && + this.req.contentCharset !== '' && + this.req.contentCharset !== null + ) { + converter.charset = this.req.contentCharset; + } else { + converter.charset = "utf-8"; + } - this.storageStream.init(8192, len, null); - this.binaryOutputStream.setOutputStream( - this.storageStream.getOutputStream(0)); - this.binaryOutputStream.writeBytes(this.data, len); + var stream = converter.convertToInputStream(this.data); try { this.listener.onDataAvailable( this.req, this.resInfo.context, this.storageStream.newInputStream(0), - 0, len); + 0, stream.available()); } catch (e) { this.req.cancel(this.req.NS_BINDING_ABORTED); } diff --git a/lib/http_observer/stream_loader.js b/lib/http_observer/stream_loader.js index cae11a7..a90e341 100644 --- a/lib/http_observer/stream_loader.js +++ b/lib/http_observer/stream_loader.js @@ -146,7 +146,7 @@ StreamListener.prototype.onDetermineCharset = function onDetermineCharset( loader.channel.contentCharset = match[1]; return match[1]; } else { - return "UTF-8"; + return "utf-8"; } } }; |