Bug 1235365: Parse WebExtension JSON files as UTF-8. r=billm

This commit is contained in:
Kris Maglione 2016-01-09 16:53:24 -08:00
parent 304bce0adf
commit 283bb006b6
7 changed files with 35 additions and 19 deletions

View File

@ -8,7 +8,7 @@ add_task(function* testTabSwitchContext() {
"page_action": {
"default_icon": "default.png",
"default_popup": "default.html",
"default_title": "Default Title",
"default_title": "Default Title \u263a",
},
"permissions": ["tabs"],
},
@ -17,10 +17,10 @@ add_task(function* testTabSwitchContext() {
let details = [
{ "icon": browser.runtime.getURL("default.png"),
"popup": browser.runtime.getURL("default.html"),
"title": "Default Title" },
"title": "Default Title \u263a" },
{ "icon": browser.runtime.getURL("1.png"),
"popup": browser.runtime.getURL("default.html"),
"title": "Default Title" },
"title": "Default Title \u263a" },
{ "icon": browser.runtime.getURL("2.png"),
"popup": browser.runtime.getURL("2.html"),
"title": "Title 2" },

View File

@ -21,6 +21,8 @@ const Cc = Components.classes;
const Cu = Components.utils;
const Cr = Components.results;
Cu.importGlobalProperties(["TextEncoder"]);
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
@ -81,6 +83,7 @@ var {
MessageBroker,
Messenger,
injectAPI,
instanceOf,
extend,
flushJarCache,
} = ExtensionUtils;
@ -522,7 +525,8 @@ ExtensionData.prototype = {
return;
}
try {
let text = NetUtil.readInputStreamToString(inputStream, inputStream.available());
let text = NetUtil.readInputStreamToString(inputStream, inputStream.available(),
{ charset: "utf-8" });
resolve(JSON.parse(text));
} catch (e) {
reject(e);
@ -832,12 +836,16 @@ this.Extension.generateXPI = function(id, data) {
let script = files[filename];
if (typeof(script) == "function") {
script = "(" + script.toString() + ")()";
} else if (typeof(script) == "object") {
} else if (instanceOf(script, "Object")) {
script = JSON.stringify(script);
}
let stream = Cc["@mozilla.org/io/string-input-stream;1"].createInstance(Ci.nsIStringInputStream);
stream.data = script;
if (!instanceOf(script, "ArrayBuffer")) {
script = new TextEncoder("utf-8").encode(script).buffer;
}
let stream = Cc["@mozilla.org/io/arraybuffer-input-stream;1"].createInstance(Ci.nsIArrayBufferInputStream);
stream.setData(script, 0, script.byteLength);
generateFile(filename);
zipW.addEntryStream(filename, time, 0, stream, false);

View File

@ -1,6 +1,7 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test for WebExtension localization APIs</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
@ -29,6 +30,8 @@ add_task(function* test_i18n() {
assertEq("??", _("@@unknown_builtin_string"), "Unknown built-in string.");
assertEq("??", _("@@bidi_unknown_builtin_string"), "Unknown built-in bidi string.");
assertEq("Føo.", _("Föo"), "Multi-byte message in selected locale.");
let substitutions = [];
substitutions[4] = "5";
substitutions[13] = "14";
@ -72,6 +75,11 @@ add_task(function* test_i18n() {
"description": "foo",
},
"föo": {
"message": "Føo.",
"description": "foo",
},
"basic_substitutions": {
"message": "'$0' '$14' '$1' '$5' '$$$$$' '$$'.",
"description": "foo",

View File

@ -1,10 +1,10 @@
{
"name": {
"message": "foo",
"message": "foo",
"description": "foo"
},
"desc": {
"message": "bar",
"message": "bar",
"description": "bar"
}
}

View File

@ -1,10 +1,10 @@
{
"name": {
"message": "le foo",
"message": "le foo",
"description": "foo"
},
"desc": {
"message": "le bar",
"message": "le bar",
"description": "bar"
}
}

View File

@ -1,6 +1,6 @@
{
"name": "Web Extension __MSG_name__",
"description": "Descripton __MSG_desc__ of add-on",
"name": "Web Extensiøn __MSG_name__",
"description": "Descriptïon __MSG_desc__ of add-on",
"version": "1.0",
"manifest_version": 2,
"default_locale": "en",

View File

@ -151,24 +151,24 @@ add_task(function* test_manifest_localization() {
let addon = yield promiseAddonByID(ID);
equal(addon.name, "Web Extension foo");
equal(addon.description, "Descripton bar of add-on");
equal(addon.name, "Web Extensiøn foo ☹");
equal(addon.description, "Descriptïon bar of add-on");
Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "fr-FR");
yield promiseRestartManager();
addon = yield promiseAddonByID(ID);
equal(addon.name, "Web Extension le foo");
equal(addon.description, "Descripton le bar of add-on");
equal(addon.name, "Web Extensiøn le foo ☺");
equal(addon.description, "Descriptïon le bar of add-on");
Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "de");
yield promiseRestartManager();
addon = yield promiseAddonByID(ID);
equal(addon.name, "Web Extension foo");
equal(addon.description, "Descripton bar of add-on");
equal(addon.name, "Web Extensiøn foo ☹");
equal(addon.description, "Descriptïon bar of add-on");
});
// Missing ID should cause a failure