fix: #8595, dont save escaped data when renaming groups

This commit is contained in:
Barış Soner Uşaklı
2020-10-20 00:24:34 -04:00
parent ea31f50554
commit b26e9b5993
3 changed files with 86 additions and 90 deletions

View File

@@ -232,7 +232,7 @@ module.exports = function (Groups) {
navItem.groups.splice(navItem.groups.indexOf(oldName), 1, newName);
}
});
navigation.unescapeFields(navItems);
await navigation.save(navItems);
}

View File

@@ -35,27 +35,37 @@ admin.getAdmin = async function () {
return { enabled: enabled, available: available };
};
const fieldsToEscape = ['iconClass', 'class', 'route', 'id', 'text', 'textClass', 'title'];
admin.escapeFields = navItems => toggleEscape(navItems, true);
admin.unescapeFields = navItems => toggleEscape(navItems, false);
function toggleEscape(navItems, flag) {
navItems.forEach(function (item) {
if (item) {
fieldsToEscape.forEach((field) => {
if (item.hasOwnProperty(field)) {
item[field] = validator[flag ? 'escape' : 'unescape'](String(item[field]));
}
});
}
});
}
admin.get = async function () {
if (cache) {
return _.cloneDeep(cache);
}
const data = await db.getSortedSetRange('navigation:enabled', 0, -1);
const escapeFields = ['iconClass', 'class', 'route', 'id', 'text', 'textClass', 'title'];
cache = data.map(function (item) {
item = JSON.parse(item);
escapeFields.forEach((field) => {
if (item.hasOwnProperty(field)) {
item[field] = validator.escape(String(item[field]));
}
});
item.groups = item.groups || [];
if (item.groups && !Array.isArray(item.groups)) {
item.groups = [item.groups];
}
return item;
});
admin.escapeFields(cache);
return _.cloneDeep(cache);
};