From b4498394793795dc7ae968c4c0295c44134c1ca9 Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Mon, 26 Aug 2024 09:59:06 +0800 Subject: [PATCH] DEV: Fix custom_header_links migration to handle blank string If the old theme setting value is set to a blank string, we will end up not migrating it and thus cause an error to be raised. --- .../settings/0002-migrate-custom-header-links.js | 2 +- .../0002-migrate-custom-header-links-test.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/migrations/settings/0002-migrate-custom-header-links.js b/migrations/settings/0002-migrate-custom-header-links.js index 63d5421..7d3fc80 100644 --- a/migrations/settings/0002-migrate-custom-header-links.js +++ b/migrations/settings/0002-migrate-custom-header-links.js @@ -8,7 +8,7 @@ export default function migrate(settings) { return settings; } - if (oldSetting) { + if (typeof oldSetting === "string") { const newLinks = []; oldSetting.split("|").forEach((link) => { diff --git a/test/unit/migrations/settings/0002-migrate-custom-header-links-test.js b/test/unit/migrations/settings/0002-migrate-custom-header-links-test.js index 8573f23..2fe2c46 100644 --- a/test/unit/migrations/settings/0002-migrate-custom-header-links-test.js +++ b/test/unit/migrations/settings/0002-migrate-custom-header-links-test.js @@ -43,6 +43,21 @@ module( ); }); + test("migrate when old setting value is an empty string", function (assert) { + const settings = new Map(Object.entries({ custom_header_links: "" })); + + const result = migrate(settings); + + const expectedResult = new Map( + Object.entries({ custom_header_links: [] }) + ); + + assert.deepEqual( + Object.fromEntries(result.entries()), + Object.fromEntries(expectedResult.entries()) + ); + }); + test("migrate when old setting value is invalid", function (assert) { const settings = new Map( Object.entries({