mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
fix: prevent crash if groups is not valid json
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const validator = require('validator');
|
const validator = require('validator');
|
||||||
|
const winston = require('winston');
|
||||||
|
|
||||||
const plugins = require('../plugins');
|
const plugins = require('../plugins');
|
||||||
const db = require('../database');
|
const db = require('../database');
|
||||||
@@ -66,7 +67,12 @@ admin.get = async function () {
|
|||||||
const data = await db.getObjects(ids.map(id => `navigation:enabled:${id}`));
|
const data = await db.getObjects(ids.map(id => `navigation:enabled:${id}`));
|
||||||
cache = data.map((item) => {
|
cache = data.map((item) => {
|
||||||
if (item.hasOwnProperty('groups')) {
|
if (item.hasOwnProperty('groups')) {
|
||||||
|
try {
|
||||||
item.groups = JSON.parse(item.groups);
|
item.groups = JSON.parse(item.groups);
|
||||||
|
} catch (err) {
|
||||||
|
winston.error(err.stack);
|
||||||
|
item.groups = [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
item.groups = item.groups || [];
|
item.groups = item.groups || [];
|
||||||
if (item.groups && !Array.isArray(item.groups)) {
|
if (item.groups && !Array.isArray(item.groups)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user