Browse Source

improve regex, fixes replacements of usernames with same trunk

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
tags/v11.0RC2
Arthur Schiwon 7 years ago
parent
commit
b21ce6ee5e
No account linked to committer's email address
1 changed files with 12 additions and 1 deletions
  1. 12
    1
      apps/comments/js/commentstabview.js

+ 12
- 1
apps/comments/js/commentstabview.js View File

@@ -256,9 +256,20 @@

for(var i in mentions) {
var mention = '@' + mentions[i].mentionId;


// escape possible regex characters in the name
mention = mention.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
var displayName = '<b>'+ _.escape(mentions[i].mentionDisplayName)+'</b>';
message = message.replace(new RegExp(mention, 'g'), displayName);

// replace every mention either at the start of the input or after a whitespace
// followed by a non-word character.
message = message.replace(new RegExp("(^|\\s)(" + mention + ")(\\b|?![_-@.])", 'g'),
function(match, p1) {
// to get number of whitespaces (0 vs 1) right
return p1+displayName;
}
);
}

return message;

Loading…
Cancel
Save