bug-librejs
[Top][All Lists]
Advanced

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

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


From: Jookia
Subject: [Bug-librejs] [PATCH] process_response: Javascript source to Unicode.
Date: Tue, 2 Jun 2015 13:36:13 +1000
User-agent: Mutt/1.5.23 (2014-03-12)

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);
         }
-- 
2.4.1




reply via email to

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