Index: lib/prefs.js |
diff --git a/lib/prefs.js b/lib/prefs.js |
index 00c52ea82147125ea94eb4005b6c3f7b5a78d123..a4618868753f05927aec825ed2089e4aaaba1bed 100644 |
--- a/lib/prefs.js |
+++ b/lib/prefs.js |
@@ -46,7 +46,14 @@ let defaults = { |
disable_auto_updates: false, |
first_run_subscription_auto_select: true, |
notifications_ignoredcategories: [], |
- allowed_connection_type: "" |
+ allowed_connection_type: null |
+}; |
+ |
+// It is for non-objects, e.g. for string, number, etc. |
+// Don't put here preferences used by adblockpluscore. |
+let nullableValues_ExpectedTypes = { |
+ __proto__: null, |
+ allowed_connection_type: "string" |
}; |
let preconfigurable = ["suppress_first_run_page", "disable_auto_updates", |
@@ -58,6 +65,14 @@ let listeners = []; |
let isDirty = false; |
let isSaving = false; |
+function isValueTypeCorrect(key, value) |
+{ |
+ let nullableValue_ExpectedType = nullableValues_ExpectedTypes[key]; |
+ return !nullableValue_ExpectedType ? |
+ typeof value == typeof defaults[key] : |
+ value === null || typeof value == nullableValue_ExpectedType; |
+} |
+ |
function defineProperty(key) |
{ |
Object.defineProperty(Prefs, key, |
@@ -65,7 +80,7 @@ function defineProperty(key) |
get: () => values[key], |
set: function(value) |
{ |
- if (typeof value != typeof defaults[key]) |
+ if (!isValueTypeCorrect(key, value)) |
throw new Error("Attempt to change preference type"); |
if (value == defaults[key]) |
@@ -142,7 +157,13 @@ let Prefs = exports.Prefs = { |
// Update the default prefs with what was preconfigured |
for (let key in _preconfiguredPrefs) |
if (preconfigurable.indexOf(key) != -1) |
- defaults[key] = _preconfiguredPrefs[key]; |
+ { |
+ let value = _preconfiguredPrefs[key]; |
+ if (!isValueTypeCorrect(key, value)) |
+ throw new Error("Unexpected value type in preconfigured preferences"); |
+ |
+ defaults[key] = value; |
+ } |
// Define defaults |
for (let key in defaults) |