summaryrefslogtreecommitdiffstats
path: root/apps/comments
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2016-10-17 18:19:51 +0200
committerArthur Schiwon <blizzz@arthur-schiwon.de>2016-10-19 00:34:00 +0200
commitb21ce6ee5e9aa0073922e7d00e5f5834863dc107 (patch)
tree7dfd78cb18f82c0d26ed64359ca19f02461f9c53 /apps/comments
parent0e926efc9be2f211eb01675d3d828a93c7b5a208 (diff)
downloadnextcloud-server-b21ce6ee5e9aa0073922e7d00e5f5834863dc107.tar.gz
nextcloud-server-b21ce6ee5e9aa0073922e7d00e5f5834863dc107.zip
improve regex, fixes replacements of usernames with same trunk
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps/comments')
-rw-r--r--apps/comments/js/commentstabview.js13
1 files changed, 12 insertions, 1 deletions
diff --git a/apps/comments/js/commentstabview.js b/apps/comments/js/commentstabview.js
index 23f2bc489e4..9c0e6a6b68c 100644
--- a/apps/comments/js/commentstabview.js
+++ b/apps/comments/js/commentstabview.js
@@ -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;