diff --git a/src/meta/title.js b/src/meta/title.js index 652001af97..0019cdb686 100644 --- a/src/meta/title.js +++ b/src/meta/title.js @@ -1,6 +1,7 @@ 'use strict'; -var user = require('../user'), +var winston = require('winston'), + user = require('../user'), translator = require('../../public/src/translator'); module.exports = function(Meta) { @@ -14,7 +15,14 @@ module.exports = function(Meta) { }; Meta.title.build = function (urlFragment, language, callback) { - Meta.title.parseFragment(decodeURIComponent(urlFragment), language, function(err, title) { + var uri = ''; + try { + uri = decodeURIComponent(urlFragment); + } catch(e) { + winston.error('Invalid url fragment : ' + urlFragment, e.stack); + return callback(null, Meta.config.browserTitle || 'NodeBB'); + } + Meta.title.parseFragment(uri, language, function(err, title) { if (err) { title = Meta.config.browserTitle || 'NodeBB'; } else { diff --git a/src/posts.js b/src/posts.js index 346965709d..6eb1e9eae9 100644 --- a/src/posts.js +++ b/src/posts.js @@ -298,7 +298,7 @@ var async = require('async'), } posts = posts.filter(function(post) { - return parseInt(results.topics[post.tid].deleted, 10) !== 1; + return results.topics[post.tid] && parseInt(results.topics[post.tid].deleted, 10) !== 1; }); async.map(posts, function(post, next) { diff --git a/src/topics.js b/src/topics.js index d43cb0fb31..395ab476fb 100644 --- a/src/topics.js +++ b/src/topics.js @@ -174,9 +174,9 @@ var async = require('async'), Topics.getTopicsData(tids, function(err, topics) { function mapFilter(array, field) { return array.map(function(topic) { - return topic[field]; + return topic && topic[field]; }).filter(function(value, index, array) { - return array.indexOf(value) === index; + return value && array.indexOf(value) === index; }); } @@ -219,21 +219,23 @@ var async = require('async'), }); for (var i=0; i