From ac460448d2068d7db367b04de95dc4595e661914 Mon Sep 17 00:00:00 2001 From: Moritz Beier Date: Mon, 13 Jan 2025 12:11:22 +0000 Subject: [PATCH] Bug 1940533 - Fix search settings v11 migration fail when going back and forth between releases. a=pascalc Original Revision: https://phabricator.services.mozilla.com/D233675 Differential Revision: https://phabricator.services.mozilla.com/D234014 --- toolkit/components/search/SearchSettings.sys.mjs | 5 +++++ .../search/tests/xpcshell/test_settings_migrate_icons.js | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/toolkit/components/search/SearchSettings.sys.mjs b/toolkit/components/search/SearchSettings.sys.mjs index 4143f90611ae0..f934a5dac721a 100644 --- a/toolkit/components/search/SearchSettings.sys.mjs +++ b/toolkit/components/search/SearchSettings.sys.mjs @@ -256,11 +256,16 @@ export class SearchSettings { sizeObj = JSON.parse(sizeStr); } catch {} if ( + typeof sizeObj === "object" && "width" in sizeObj && parseInt(sizeObj.width) > 0 && sizeObj.width == sizeObj.height ) { engine._iconMapObj[sizeObj.width] = icon; + } else if (typeof sizeObj === "number") { + // This happens if the user copies a version 11+ search config to + // an old install, which gets updated eventually; see bug 1940533. + engine._iconMapObj[sizeObj] = icon; } } } diff --git a/toolkit/components/search/tests/xpcshell/test_settings_migrate_icons.js b/toolkit/components/search/tests/xpcshell/test_settings_migrate_icons.js index 0f3972d2029fc..9c3587647c038 100644 --- a/toolkit/components/search/tests/xpcshell/test_settings_migrate_icons.js +++ b/toolkit/components/search/tests/xpcshell/test_settings_migrate_icons.js @@ -28,6 +28,8 @@ const SEARCH_SETTINGS = { '{"width":42,"height":41}': "data:image/png;base64,ico42", "{}": "data:image/png;base64,ico0", "invalid json": "data:image/png;base64,ico0", + // Going back and forth should work. + 64: "data:image/png;base64,ico64", }, _metaData: { loadPathHash: "OixanEC3I3fSEnZY/YeX1YndC9qdzkqotEEKsodghLY=", @@ -81,7 +83,7 @@ add_task(async function test_icon_migration() { Assert.equal( Object.keys(engine.wrappedJSObject._iconMapObj).length, - 2, + 3, "Only valid _iconMapObj keys got converted." ); Assert.ok( @@ -94,5 +96,6 @@ add_task(async function test_icon_migration() { Assert.ok((await engine.getIconURL()).includes("ico16")); Assert.ok((await engine.getIconURL(16)).includes("ico16")); Assert.ok((await engine.getIconURL(32)).includes("ico32")); + Assert.ok((await engine.getIconURL(64)).includes("ico64")); Assert.ok((await engine.getIconURL(74)).includes("ico74")); });