From dbf07f786d63525a9c488d8f47b97dfc7a323380 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Fri, 23 May 2014 15:01:06 -0400 Subject: [PATCH] closes #1565 --- public/src/modules/composer/tags.js | 3 ++- src/topics/tags.js | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/public/src/modules/composer/tags.js b/public/src/modules/composer/tags.js index 4f6a6294f4..e5b1a34b83 100644 --- a/public/src/modules/composer/tags.js +++ b/public/src/modules/composer/tags.js @@ -13,7 +13,8 @@ define(function() { } tagEl.tagsinput({ - maxTags: config.tagsPerTopic + maxTags: config.tagsPerTopic, + confirmKeys: [13, 188] }); addTags(postData.tags, tagEl); diff --git a/src/topics/tags.js b/src/topics/tags.js index 492723f750..63e67eddd4 100644 --- a/src/topics/tags.js +++ b/src/topics/tags.js @@ -11,9 +11,13 @@ module.exports = function(Topics) { Topics.createTags = function(tags, tid, timestamp, callback) { if(Array.isArray(tags)) { tags = tags.slice(0, meta.config.tagsPerTopic || 5); + async.each(tags, function(tag, next) { - tag = utils.removePunctuation(tag.trim().toLowerCase()).substr(0, meta.config.maximumTagLength || 15); + tag = cleanUpTag(tag); + if (tag.length < (meta.config.minimumTagLength || 3)) { + return next(); + } db.setAdd('topic:' + tid + ':tags', tag); db.sortedSetAdd('tag:' + tag + ':topics', timestamp, tid, function(err) { @@ -26,6 +30,17 @@ module.exports = function(Topics) { } }; + function cleanUpTag(tag) { + tag = tag.trim().toLowerCase(); + var matches = tag.match(/^-*(.+?)-*$/); + if (matches && matches.length > 1) { + tag = matches[1]; + } + tag = tag.replace(/[\.,\/#!$%\^&\*;:{}=_`<>'"~()?\|]/g, ''); + tag = tag.substr(0, meta.config.maximumTagLength || 15); + return tag; + } + function updateTagCount(tag) { Topics.getTagTopicCount(tag, function(err, count) { if (!err) {