DEV: Fix custom_header_links migration to handle blank string (#69)

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.
This commit is contained in:
Alan Guo Xiang Tan 2024-08-26 14:39:05 +08:00 committed by GitHub
parent 82d5925f31
commit 1edd930d33
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 1 deletions

View File

@ -8,7 +8,7 @@ export default function migrate(settings) {
return settings;
}
if (oldSetting) {
if (typeof oldSetting === "string") {
const newLinks = [];
oldSetting.split("|").forEach((link) => {

View File

@ -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({