mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-14 09:55:47 +01:00
remove punctuation and limit tag length
This commit is contained in:
@@ -126,6 +126,9 @@
|
||||
return str;
|
||||
},
|
||||
|
||||
removePunctuation: function(str) {
|
||||
return str.replace(/[\.,-\/#!$%\^&\*;:{}=\-_`~()?]/g, '');
|
||||
},
|
||||
|
||||
isEmailValid: function(email) {
|
||||
return typeof email === 'string' && email.length && email.indexOf('@') !== -1;
|
||||
|
||||
@@ -54,14 +54,13 @@ module.exports = function(Topics) {
|
||||
db.sortedSetAdd('topics:tid', timestamp, tid);
|
||||
plugins.fireHook('action:topic.save', tid);
|
||||
|
||||
Topics.createTags(data.tags, tid, timestamp);
|
||||
user.addTopicIdToUser(uid, tid, timestamp);
|
||||
|
||||
db.sortedSetAdd('categories:' + cid + ':tid', timestamp, tid);
|
||||
db.incrObjectField('category:' + cid, 'topic_count');
|
||||
db.incrObjectField('global', 'topicCount');
|
||||
|
||||
Topics.createTags(data.tags, tid, timestamp);
|
||||
|
||||
callback(null, tid);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,14 +2,16 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async'),
|
||||
db = require('../database');
|
||||
db = require('../database'),
|
||||
utils = require('../../public/src/utils');
|
||||
|
||||
module.exports = function(Topics) {
|
||||
|
||||
Topics.createTags = function(tags, tid, timestamp) {
|
||||
if(Array.isArray(tags)) {
|
||||
for (var i=0; i<tags.length; ++i) {
|
||||
tags[i] = tags[i].trim().toLowerCase();
|
||||
tags[i] = utils.removePunctuation(tags[i].trim().toLowerCase()).substr(0, 20); // TODO: make max length configurable
|
||||
|
||||
db.sortedSetAdd('tag:' + tags[i] + ':topics', timestamp, tid);
|
||||
db.setAdd('topic:' + tid + ':tags', tags[i]);
|
||||
db.setAdd('tags', tags[i]);
|
||||
|
||||
Reference in New Issue
Block a user