From 2fd121dc15a731bc7503515f4a8673052ad3b9e5 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Sat, 13 Feb 2016 09:35:48 +0200 Subject: [PATCH] #4154 --- src/groups.js | 4 ++-- src/search.js | 59 +++++++++++++++++++++++++-------------------------- 2 files changed, 31 insertions(+), 32 deletions(-) diff --git a/src/groups.js b/src/groups.js index 30fefa466f..c318db9942 100644 --- a/src/groups.js +++ b/src/groups.js @@ -241,8 +241,8 @@ var utils = require('../public/src/utils'); if (group) { group.nameEncoded = encodeURIComponent(group.name); group.displayName = validator.escape(group.name); - group.description = validator.escape(group.description); - group.userTitle = validator.escape(group.userTitle) || group.displayName; + group.description = validator.escape(group.description || ''); + group.userTitle = validator.escape(group.userTitle || '') || group.displayName; } }; diff --git a/src/search.js b/src/search.js index e6975a893e..ca457d8b0b 100644 --- a/src/search.js +++ b/src/search.js @@ -1,45 +1,44 @@ 'use strict'; -var async = require('async'), - validator = require('validator'), - - db = require('./database'), - posts = require('./posts'), - topics = require('./topics'), - categories = require('./categories'), - user = require('./user'), - plugins = require('./plugins'), - privileges = require('./privileges'), - utils = require('../public/src/utils'); +var async = require('async'); +var validator = require('validator'); + +var db = require('./database'); +var posts = require('./posts'); +var topics = require('./topics'); +var categories = require('./categories'); +var user = require('./user'); +var plugins = require('./plugins'); +var privileges = require('./privileges'); +var utils = require('../public/src/utils'); var search = {}; module.exports = search; search.search = function(data, callback) { - function done(err, result) { - if (err) { - return callback(err); - } - - result.search_query = validator.escape(data.query); - result.time = (process.elapsedTimeSince(start) / 1000).toFixed(2); - callback(null, result); - } var start = process.hrtime(); - var searchIn = data.searchIn || 'titlesposts'; - if (searchIn === 'posts' || searchIn === 'titles' || searchIn === 'titlesposts') { - searchInContent(data, done); - } else if (searchIn === 'users') { - user.search(data, done); - } else if (searchIn === 'tags') { - topics.searchAndLoadTags(data, done); - } else { - callback(new Error('[[error:unknown-search-filter]]')); - } + async.waterfall([ + function (next) { + if (searchIn === 'posts' || searchIn === 'titles' || searchIn === 'titlesposts') { + searchInContent(data, next); + } else if (searchIn === 'users') { + user.search(data, next); + } else if (searchIn === 'tags') { + topics.searchAndLoadTags(data, next); + } else { + next(new Error('[[error:unknown-search-filter]]')); + } + }, + function (result, next) { + result.search_query = validator.escape(data.query || ''); + result.time = (process.elapsedTimeSince(start) / 1000).toFixed(2); + next(null, result); + } + ], callback); }; function searchInContent(data, callback) {