mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-24 00:09:41 +01:00
fix: #8595, dont save escaped data when renaming groups
This commit is contained in:
@@ -232,7 +232,7 @@ module.exports = function (Groups) {
|
||||
navItem.groups.splice(navItem.groups.indexOf(oldName), 1, newName);
|
||||
}
|
||||
});
|
||||
|
||||
navigation.unescapeFields(navItems);
|
||||
await navigation.save(navItems);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user