[Pkg-mozext-commits] [wot] 173/226: Fixed #72 Comment's encoding issue

David Prévot taffit at moszumanska.debian.org
Fri May 1 00:35:48 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository wot.

commit ebe5179f27e2722c51d499452af314087d347b6c
Author: Sergey Andryukhin <sorgoz at yandex.com>
Date:   Mon Sep 23 22:38:48 2013 +0300

    Fixed #72 Comment's encoding issue
---
 content/api.js               |  9 ++++-----
 content/prefs.js             | 20 ++++++++++++++++++++
 content/rw/ratingwindow.html |  2 +-
 content/util.js              | 19 +++++++++++++++++++
 4 files changed, 44 insertions(+), 6 deletions(-)

diff --git a/content/api.js b/content/api.js
index 75a3184..96b6eb9 100644
--- a/content/api.js
+++ b/content/api.js
@@ -1152,7 +1152,7 @@ var wot_keeper = {
             status: status || wot_keeper.STATUSES.LOCAL
         };
 
-        wot_keeper.store_by_name(target, "comment", JSON.stringify(data));
+        wot_keeper.store_by_name(target, "comment", data);
     },
 
     remove_comment: function (target) {
@@ -1166,17 +1166,16 @@ var wot_keeper = {
 //        console.log("keeper.get_by_name()", target, name);
 
         try {
-            var json = wot_prefs.getChar(wot_keeper._fullname(target, name), true) || null;
-            return json ? JSON.parse(json) : null;
+            return wot_prefs.getJSON(wot_keeper._fullname(target, name)) || null;
         } catch (e) {
             wdump("wot_keeper.get_by_name() Failed with " + e);
         }
         return null;
     },
 
-    store_by_name: function (target, name, data) {
+    store_by_name: function (target, name, obj) {
 //        console.log("keeper.store_by_name()", target, name, data);
-        wot_prefs.setChar(wot_keeper._fullname(target, name), data, true);
+        wot_prefs.setJSON(wot_keeper._fullname(target, name), obj);
     },
 
     remove_by_name: function (target, name) {
diff --git a/content/prefs.js b/content/prefs.js
index c2634c7..52cdfad 100644
--- a/content/prefs.js
+++ b/content/prefs.js
@@ -210,6 +210,26 @@ var wot_prefs =
 		return false;
 	},
 
+    getJSON: function (name, default_value) {
+        try {
+            var json = this.getChar(name, null, false);
+            return json ? JSON.parse(wot_util.utf8_to_unicode(json)) : default_value;
+        } catch (e) {
+            wdump("wot_prefs.getJSON(" + name + "): failed with " + e);
+            return default_value;
+        }
+    },
+
+    setJSON: function (name, obj) {
+        try {
+            var json = JSON.stringify(obj);
+            return this.setChar(name, wot_util.unicode_to_utf8(json), false);
+        } catch (e) {
+            wdump("wot_prefs.getJSON(" + name + "): failed with " + e);
+            return false;
+        }
+    },
+
 	clear: function(name)
 	{
 		try {
diff --git a/content/rw/ratingwindow.html b/content/rw/ratingwindow.html
index 548145a..35c2629 100644
--- a/content/rw/ratingwindow.html
+++ b/content/rw/ratingwindow.html
@@ -1,4 +1,3 @@
-<?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE html>
 
 <!--
@@ -23,6 +22,7 @@
 
 <html>
 <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
     <script type="text/javascript" src="chrome://wot/content/libs/jquery.js"></script>
     <script type="text/javascript" src="chrome://wot/content/libs/jquery.menu-aim.js"></script>
     <script type="text/javascript" src="chrome://wot/content/rw/wot.js"></script>
diff --git a/content/util.js b/content/util.js
index 9e228f9..d2168a3 100644
--- a/content/util.js
+++ b/content/util.js
@@ -122,6 +122,25 @@ var wot_util =
         return decodeURIComponent(escape(s));
     },
 
+    utf8_to_unicode: function (str) {
+        if (!str) return null;
+        var converter = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"]
+            .createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
+        converter.charset = "UTF-8";
+
+        return converter.ConvertToUnicode(str);
+    },
+
+    unicode_to_utf8: function (str) {
+        var converter = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"]
+            .createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
+        converter.charset = "UTF-8";
+
+        var encoded = converter.ConvertFromUnicode(str);
+        return encoded + converter.Finish();
+
+    },
+
 	time_sincefirstrun: function()
 	{
 		try {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/wot.git



More information about the Pkg-mozext-commits mailing list