mirror of
https://github.com/gorhill/uBlock.git
synced 2024-10-04 08:37:11 +02:00
get/setComplexValue must be used to ensure proper handling of Unicode string in `about:config`.
This commit is contained in:
parent
f29628ee01
commit
5366697a0c
@ -351,7 +351,7 @@ vAPI.storage = (function() {
|
|||||||
|
|
||||||
var row;
|
var row;
|
||||||
|
|
||||||
while ( row = rows.getNextRow() ) {
|
while ( (row = rows.getNextRow()) ) {
|
||||||
// we assume that there will be two columns, since we're
|
// we assume that there will be two columns, since we're
|
||||||
// using it only for preferences
|
// using it only for preferences
|
||||||
result[row.getResultByIndex(0)] = row.getResultByIndex(1);
|
result[row.getResultByIndex(0)] = row.getResultByIndex(1);
|
||||||
@ -2936,6 +2936,13 @@ vAPI.cloud = (function() {
|
|||||||
var extensionBranchPath = 'extensions.' + location.host;
|
var extensionBranchPath = 'extensions.' + location.host;
|
||||||
var cloudBranchPath = extensionBranchPath + '.cloudStorage';
|
var cloudBranchPath = extensionBranchPath + '.cloudStorage';
|
||||||
|
|
||||||
|
// https://github.com/gorhill/uBlock/issues/80#issuecomment-132081658
|
||||||
|
// We must use get/setComplexValue in order to properly handle strings
|
||||||
|
// with unicode characters.
|
||||||
|
var iss = Ci.nsISupportsString;
|
||||||
|
var argstr = Components.classes['@mozilla.org/supports-string;1']
|
||||||
|
.createInstance(iss);
|
||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
defaultDeviceName: '',
|
defaultDeviceName: '',
|
||||||
deviceName: ''
|
deviceName: ''
|
||||||
@ -2945,7 +2952,8 @@ vAPI.cloud = (function() {
|
|||||||
try {
|
try {
|
||||||
options.deviceName = Services.prefs
|
options.deviceName = Services.prefs
|
||||||
.getBranch(extensionBranchPath + '.')
|
.getBranch(extensionBranchPath + '.')
|
||||||
.getCharPref('deviceName');
|
.getComplexValue('deviceName', iss)
|
||||||
|
.data;
|
||||||
} catch(ex) {
|
} catch(ex) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2954,7 +2962,8 @@ vAPI.cloud = (function() {
|
|||||||
try {
|
try {
|
||||||
name = Services.prefs
|
name = Services.prefs
|
||||||
.getBranch('services.sync.client.')
|
.getBranch('services.sync.client.')
|
||||||
.getCharPref('name');
|
.getComplexValue('name', iss)
|
||||||
|
.data;
|
||||||
} catch(ex) {
|
} catch(ex) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2966,11 +2975,12 @@ vAPI.cloud = (function() {
|
|||||||
var syncBranch = Services.prefs.getBranch('services.sync.prefs.sync.');
|
var syncBranch = Services.prefs.getBranch('services.sync.prefs.sync.');
|
||||||
|
|
||||||
// Mark config entries as syncable
|
// Mark config entries as syncable
|
||||||
|
argstr.data = '';
|
||||||
var dataKey;
|
var dataKey;
|
||||||
for ( var i = 0; i < dataKeys.length; i++ ) {
|
for ( var i = 0; i < dataKeys.length; i++ ) {
|
||||||
dataKey = dataKeys[i];
|
dataKey = dataKeys[i];
|
||||||
if ( extensionBranch.prefHasUserValue('cloudStorage.' + dataKey) === false ) {
|
if ( extensionBranch.prefHasUserValue('cloudStorage.' + dataKey) === false ) {
|
||||||
extensionBranch.setCharPref('cloudStorage.' + dataKey, '');
|
extensionBranch.setComplexValue('cloudStorage.' + dataKey, iss, argstr);
|
||||||
}
|
}
|
||||||
syncBranch.setBoolPref(cloudBranchPath + '.' + dataKey, true);
|
syncBranch.setBoolPref(cloudBranchPath + '.' + dataKey, true);
|
||||||
}
|
}
|
||||||
@ -2985,7 +2995,8 @@ vAPI.cloud = (function() {
|
|||||||
'size': 0
|
'size': 0
|
||||||
};
|
};
|
||||||
bin.size = JSON.stringify(bin).length;
|
bin.size = JSON.stringify(bin).length;
|
||||||
branch.setCharPref(datakey, JSON.stringify(bin));
|
argstr.data = JSON.stringify(bin);
|
||||||
|
branch.setComplexValue(datakey, iss, argstr);
|
||||||
if ( typeof callback === 'function' ) {
|
if ( typeof callback === 'function' ) {
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
@ -2995,7 +3006,7 @@ vAPI.cloud = (function() {
|
|||||||
var result = null;
|
var result = null;
|
||||||
var branch = Services.prefs.getBranch(cloudBranchPath + '.');
|
var branch = Services.prefs.getBranch(cloudBranchPath + '.');
|
||||||
try {
|
try {
|
||||||
var json = branch.getCharPref(datakey);
|
var json = branch.getComplexValue(datakey, iss).data;
|
||||||
if ( typeof json === 'string' ) {
|
if ( typeof json === 'string' ) {
|
||||||
result = JSON.parse(json);
|
result = JSON.parse(json);
|
||||||
}
|
}
|
||||||
@ -3020,7 +3031,8 @@ vAPI.cloud = (function() {
|
|||||||
var branch = Services.prefs.getBranch(extensionBranchPath + '.');
|
var branch = Services.prefs.getBranch(extensionBranchPath + '.');
|
||||||
|
|
||||||
if ( typeof details.deviceName === 'string' ) {
|
if ( typeof details.deviceName === 'string' ) {
|
||||||
branch.setCharPref('deviceName', details.deviceName);
|
argstr.data = details.deviceName;
|
||||||
|
branch.setComplexValue('deviceName', iss, argstr);
|
||||||
options.deviceName = details.deviceName;
|
options.deviceName = details.deviceName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user