Node.js based forum software built for the modern web
prevent possible crash if category.posts is undefined
Barış Soner Uşaklı157a7d1f0ed0
diff --git a/src/categories/recentreplies.js b/src/categories/recentreplies.jsindex e4262ab7cb..c7b8bd5c9a 100644--- a/src/categories/recentreplies.js+++ b/src/categories/recentreplies.js@@ -166,9 +166,7 @@ module.exports = function (Categories) {var posts = [];getPostsRecursive(category, posts);- posts.sort(function (a, b) {- return b.pid - a.pid;- });+ posts.sort((a, b) => b.pid - a.pid);if (posts.length) {category.posts = [posts[0]];}@@ -176,9 +174,11 @@ module.exports = function (Categories) {}function getPostsRecursive(category, posts) {- category.posts.forEach(function (p) {- posts.push(p);- });+ if (Array.isArray(category.posts)) {+ category.posts.forEach(function (p) {+ posts.push(p);+ });+ }category.children.forEach(function (child) {getPostsRecursive(child, posts);