getComplexValue fails for empty strings

NEW
Unassigned

Status

()

Firefox
Preferences
2 years ago
2 years ago

People

(Reporter: mkaply, Unassigned)

Tracking

45 Branch
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

2 years ago
I'm working on distribution code trying to unset a complex preference and I've discovered that if you set a complex preference to an empty value, getting the value fails with

Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIPrefBranch.getComplexValue]"  nsresult: "0x80004005 (NS_ERROR_FAILURE)"

It should just return an empty string. You can see the problem with this code in a browser scratchpad:

var defaults = Services.prefs.getDefaultBranch(null);
var localizedStr = Cc["@mozilla.org/pref-localizedstring;1"].createInstance(Ci.nsIPrefLocalizedString);
var key = "foo";
var value = "";
localizedStr.data = "data:text/plain," + key + "=" + value;
defaults.setComplexValue(key, Ci.nsIPrefLocalizedString, localizedStr);
defaults.getComplexValue(key, Ci.nsIPrefLocalizedString).data;

Changing value to something other than an empty string works fine.

and the value in preferences is correct - it shows:

data:text/plain,foo=
You need to log in before you can comment on or make changes to this bug.