From 157a7d1f0ed082f20345b9523ab4826dab1483d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Mon, 12 Nov 2018 14:04:38 -0500 Subject: [PATCH] prevent possible crash if category.posts is undefined --- src/categories/recentreplies.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/categories/recentreplies.js b/src/categories/recentreplies.js index 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);