summaryrefslogtreecommitdiffstats
path: root/src/main/java/com/gitblit/tickets/TicketNotifier.java
diff options
context:
space:
mode:
authorFlorian Zschocke <florian.zschocke@devolo.de>2016-12-10 16:02:21 +0100
committerFlorian Zschocke <florian.zschocke@devolo.de>2016-12-10 16:17:21 +0100
commit7985115bd1301db867935b52a689ccfc32f13794 (patch)
tree021ec7ae22b4817ec2008b0cd2b2a9ed48d73e22 /src/main/java/com/gitblit/tickets/TicketNotifier.java
parent0e4eebcfd98d079c93c33510284cdfe976e27725 (diff)
downloadgitblit-merged--fixMentionsInTickets-985.tar.gz
gitblit-merged--fixMentionsInTickets-985.zip
Fix user mention regular expression and group replacement.merged--fixMentionsInTickets-985
The regular expression used for user mentions used to work only inside sentences. Also, since it tested for whitespace, the whitespace would get replaced, too, which would join lines together. Instead the new regex uses boundary matchers to match against word boundaires. As these are not capturing only the actual user mention can be captured and is then replaced. Also, this way the regex can ignore punctuation like in "@jim, look at this." Since Gibtlit now requires Java 7 we can use named capture groups. This makes the use of a centrally defined regular expression much safer. The (admittedly only) group to capture the user name is named "user" and can be referenced by this name. By using the name instead of a group number, the regex could be changed without the code using it breaking because the group number changed. A simple test is added for user mentions, which unfortunately has to deal with the full markdown replacement, too. Fixes #985
Diffstat (limited to 'src/main/java/com/gitblit/tickets/TicketNotifier.java')
-rw-r--r--src/main/java/com/gitblit/tickets/TicketNotifier.java2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/main/java/com/gitblit/tickets/TicketNotifier.java b/src/main/java/com/gitblit/tickets/TicketNotifier.java
index 1d7e4f24..b913db25 100644
--- a/src/main/java/com/gitblit/tickets/TicketNotifier.java
+++ b/src/main/java/com/gitblit/tickets/TicketNotifier.java
@@ -576,7 +576,7 @@ public class TicketNotifier {
Pattern p = Pattern.compile(Constants.REGEX_TICKET_MENTION);
Matcher m = p.matcher(lastChange.comment.text);
while (m.find()) {
- String username = m.group();
+ String username = m.group("user");
ccs.add(username);
}
}