From 5696ea239633151d5adb6fade0dfa8b2d7805d7e Mon Sep 17 00:00:00 2001 From: barisusakli Date: Tue, 9 Sep 2014 22:09:27 -0400 Subject: [PATCH 1/5] check errors on decodeURIComponent --- src/meta/title.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/meta/title.js b/src/meta/title.js index 652001af97..1de916ebec 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); + return callback(null, Meta.config.browserTitle || 'NodeBB'); + } + Meta.title.parseFragment(uri, language, function(err, title) { if (err) { title = Meta.config.browserTitle || 'NodeBB'; } else { From e9798028deadf79605353aebc4bf6d65e37d12ed Mon Sep 17 00:00:00 2001 From: barisusakli Date: Tue, 9 Sep 2014 22:10:17 -0400 Subject: [PATCH 2/5] show error --- src/meta/title.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/meta/title.js b/src/meta/title.js index 1de916ebec..00e5697a2d 100644 --- a/src/meta/title.js +++ b/src/meta/title.js @@ -19,7 +19,7 @@ module.exports = function(Meta) { try { uri = decodeURIComponent(urlFragment); } catch(e) { - winston.error('Invalid url fragment :' + urlFragment); + winston.error('Invalid url fragment : ' + urlFragment, e.message); return callback(null, Meta.config.browserTitle || 'NodeBB'); } Meta.title.parseFragment(uri, language, function(err, title) { From 25ed131b13392bc89c5e0d631927b8230052f7c9 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Wed, 10 Sep 2014 13:04:57 -0400 Subject: [PATCH 3/5] show stack trace of error --- src/meta/title.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/meta/title.js b/src/meta/title.js index 00e5697a2d..0019cdb686 100644 --- a/src/meta/title.js +++ b/src/meta/title.js @@ -19,7 +19,7 @@ module.exports = function(Meta) { try { uri = decodeURIComponent(urlFragment); } catch(e) { - winston.error('Invalid url fragment : ' + urlFragment, e.message); + winston.error('Invalid url fragment : ' + urlFragment, e.stack); return callback(null, Meta.config.browserTitle || 'NodeBB'); } Meta.title.parseFragment(uri, language, function(err, title) { From ae02c1a06ca57ba2f7d32dce2bcf6642a627a783 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Wed, 10 Sep 2014 18:48:43 -0400 Subject: [PATCH 4/5] closes #2068 --- src/posts.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/posts.js b/src/posts.js index 53a11e9d6b..856145c4c0 100644 --- a/src/posts.js +++ b/src/posts.js @@ -357,7 +357,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) { From 6bde9a16562a808443484c179bf7f8aaf4b7bf12 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Sat, 13 Sep 2014 19:33:09 -0400 Subject: [PATCH 5/5] prevent getTopicsByTids crash if a topic is null --- src/topics.js | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/topics.js b/src/topics.js index 9bde8159be..18b25c7c32 100644 --- a/src/topics.js +++ b/src/topics.js @@ -172,9 +172,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; }); } @@ -225,21 +225,23 @@ var async = require('async'), }); for (var i=0; i