bug-librejs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-librejs] [PATCH] process_response: Javascript source to Unicode


From: Nik Nyby
Subject: Re: [Bug-librejs] [PATCH] process_response: Javascript source to Unicode.
Date: Thu, 11 Jun 2015 09:08:47 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0

On 06/01/2015 11:36 PM, Jookia wrote:
This replaces the current binary stream with a quick Unicode conversion, fixing
the problem of mangled Unicode characters.
---
  lib/http_observer/process_response.js | 29 ++++++++++-------------------
  1 file changed, 10 insertions(+), 19 deletions(-)

diff --git a/lib/http_observer/process_response.js 
b/lib/http_observer/process_response.js
index c1f5e88..d8b1535 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,23 @@ var processResponseObject = {
jsListenerCallback: function () { - var len = this.data.length;
+        var converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"]
+            .createInstance(Ci.nsIScriptableUnicodeConverter);
- this.genBinaryOutput();
+        if (this.req.contentCharset != undefined && this.req.contentCharset != 
"") {
+            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);
+                stream,
+                0, stream.available());
          } catch (e) {
              this.req.cancel(this.req.NS_BINDING_ABORTED);
          }
Thanks! I'll apply this soon.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]