diff --git a/browser/components/nsBrowserGlue.js b/browser/components/nsBrowserGlue.js index f935f517140..71650941813 100644 --- a/browser/components/nsBrowserGlue.js +++ b/browser/components/nsBrowserGlue.js @@ -1623,11 +1623,25 @@ BrowserGlue.prototype = { // Reset homepage pref for users who have it set to start.mozilla.org // or google.com/firefox. const HOMEPAGE_PREF = "browser.startup.homepage"; - let uri = Services.prefs.getComplexValue(HOMEPAGE_PREF, - Ci.nsIPrefLocalizedString).data; - if (uri && (uri.startsWith("http://start.mozilla.org") || - /^https?:\/\/(www\.)?google\.[a-z.]+\/firefox/i.test(uri))) { - Services.prefs.clearUserPref(HOMEPAGE_PREF); + if (Services.prefs.prefHasUserValue(HOMEPAGE_PREF)) { + const DEFAULT = + Services.prefs.getDefaultBranch(HOMEPAGE_PREF) + .getComplexValue("", Ci.nsIPrefLocalizedString).data; + let value = + Services.prefs.getComplexValue(HOMEPAGE_PREF, Ci.nsISupportsString); + let updated = + value.data.replace(/https?:\/\/start\.mozilla\.org[^|]*/i, DEFAULT) + .replace(/https?:\/\/(www\.)?google\.[a-z.]+\/firefox[^|]*/i, + DEFAULT); + if (updated != value.data) { + if (updated == DEFAULT) { + Services.prefs.clearUserPref(HOMEPAGE_PREF); + } else { + value.data = updated; + Services.prefs.setComplexValue(HOMEPAGE_PREF, + Ci.nsISupportsString, value); + } + } } }