Buxfixed: if username contains space, it will cause @ commment failed to send out email and other

This commit is contained in:
Sam X. Chen 2019-09-19 15:16:48 -04:00
parent f29d7daa1d
commit 4ee88e026e
2 changed files with 39 additions and 25 deletions

View file

@ -94,7 +94,13 @@ Template.editor.onRendered(() => {
currentBoard currentBoard
.activeMembers() .activeMembers()
.map(member => { .map(member => {
const username = Users.findOne(member.userId).username; const user = Users.findOne(member.userId);
if (user._id === Meteor.userId()) {
return null;
}
const value = user.username;
const username =
value && value.match(/\s+/) ? `"${value}"` : value;
return username.includes(term) ? username : null; return username.includes(term) ? username : null;
}) })
.filter(Boolean), .filter(Boolean),
@ -120,9 +126,10 @@ Template.editor.onRendered(() => {
? [ ? [
['view', ['fullscreen']], ['view', ['fullscreen']],
['table', ['table']], ['table', ['table']],
['font', ['bold', 'underline']], ['font', ['bold']],
//['fontsize', ['fontsize']],
['color', ['color']], ['color', ['color']],
['insert', ['video']], // iframe tag will be sanitized TODO if iframe[class=note-video-clip] can be added into safe list, insert video can be enabled
//['fontsize', ['fontsize']],
] ]
: [ : [
['style', ['style']], ['style', ['style']],
@ -345,11 +352,12 @@ Blaze.Template.registerHelper(
} }
return member; return member;
}); });
const mentionRegex = /\B@([\w.]*)/gi; const mentionRegex = /\B@(?:(?:"([\w.\s]*)")|([\w.]+))/gi; // including space in username
let currentMention; let currentMention;
while ((currentMention = mentionRegex.exec(content)) !== null) { while ((currentMention = mentionRegex.exec(content)) !== null) {
const [fullMention, username] = currentMention; const [fullMention, quoteduser, simple] = currentMention;
const username = quoteduser || simple;
const knowedUser = _.findWhere(knowedUsers, { username }); const knowedUser = _.findWhere(knowedUsers, { username });
if (!knowedUser) { if (!knowedUser) {
continue; continue;

View file

@ -180,28 +180,34 @@ if (Meteor.isServer) {
const comment = activity.comment(); const comment = activity.comment();
params.comment = comment.text; params.comment = comment.text;
if (board) { if (board) {
const atUser = /(?:^|>|\b|\s)@(\S+?)(?:\s|$|<|\b)/g;
const comment = params.comment; const comment = params.comment;
if (comment.match(atUser)) { const knownUsers = board.members.map(member => {
const commenter = params.user; const u = Users.findOne(member.userId);
while (atUser.exec(comment)) { if (u) {
const username = RegExp.$1; member.username = u.username;
if (commenter === username) { member.emails = u.emails;
// it's person at himself, ignore it?
continue;
}
const atUser =
Users.findOne(username) || Users.findOne({ username });
if (atUser && atUser._id) {
const uid = atUser._id;
params.atUsername = username;
params.atEmails = atUser.emails;
if (board.hasMember(uid)) {
title = 'act-atUserComment';
watchers = _.union(watchers, [uid]);
}
}
} }
return member;
});
const mentionRegex = /\B@(?:(?:"([\w.\s]*)")|([\w.]+))/gi; // including space in username
let currentMention;
while ((currentMention = mentionRegex.exec(comment)) !== null) {
/*eslint no-unused-vars: ["error", { "varsIgnorePattern": "[iI]gnored" }]*/
const [ignored, quoteduser, simple] = currentMention;
const username = quoteduser || simple;
if (username === params.user) {
// ignore commenter mention himself?
continue;
}
const atUser = _.findWhere(knownUsers, { username });
if (!atUser) {
continue;
}
const uid = atUser.userId;
params.atUsername = username;
params.atEmails = atUser.emails;
title = 'act-atUserComment';
watchers = _.union(watchers, [uid]);
} }
} }
params.commentId = comment._id; params.commentId = comment._id;