From ea83be50a1689327786e8ff32fb84a1f523a5e2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Mon, 11 Dec 2017 11:21:22 -0500 Subject: [PATCH] closes #6161 --- src/search.js | 6 +++--- test/search.js | 11 +++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/search.js b/src/search.js index 71f212632e..4d2560e6cf 100644 --- a/src/search.js +++ b/src/search.js @@ -209,7 +209,7 @@ function getMatchedPosts(pids, data, callback) { db.getObjectsFields(cids, categoryFields, next); }, tags: function (next) { - if (data.hasTags && data.hasTags.length) { + if (Array.isArray(data.hasTags) && data.hasTags.length) { var tids = posts.map(function (post) { return post && post.tid; }); @@ -299,10 +299,10 @@ function filterByTimerange(posts, timeRange, timeFilter) { } function filterByTags(posts, hasTags) { - if (hasTags && hasTags.length) { + if (Array.isArray(hasTags) && hasTags.length) { posts = posts.filter(function (post) { var hasAllTags = false; - if (post && post.topic && post.topic.tags && post.topic.tags.length) { + if (post && post.topic && Array.isArray(post.topic.tags) && post.topic.tags.length) { hasAllTags = hasTags.every(function (tag) { return post.topic.tags.indexOf(tag) !== -1; }); diff --git a/test/search.js b/test/search.js index 119f833a80..9610b3b0c2 100644 --- a/test/search.js +++ b/test/search.js @@ -165,4 +165,15 @@ describe('Search', function () { done(); }); }); + + it('should not crash if tags is not an array', function (done) { + search.search({ + query: 'mongodb', + searchIn: 'titles', + hasTags: 'nodebb,javascript', + }, function (err, data) { + assert.ifError(err); + done(); + }); + }); });