Skip to content

Commit

Permalink
Use REGEX_TICKET_MENTION instead of hardcoded regular expression
Browse files Browse the repository at this point in the history
  • Loading branch information
RedShift1 authored and fzs committed Dec 10, 2016
1 parent a1d8cfc commit 0e4eebc
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/main/java/com/gitblit/models/TicketModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@

import org.eclipse.jgit.util.RelativeDateFormatter;

import com.gitblit.Constants;

/**
* The Gitblit Ticket model, its component classes, and enums.
*
Expand Down Expand Up @@ -773,7 +775,7 @@ public Comment comment(String text) {
}

try {
Pattern mentions = Pattern.compile("\\s@([A-Za-z0-9-_]+)");
Pattern mentions = Pattern.compile(Constants.REGEX_TICKET_MENTION);
Matcher m = mentions.matcher(text);
while (m.find()) {
String username = m.group(1);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/gitblit/tickets/TicketNotifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ protected void setRecipients(TicketModel ticket, Mailing mailing) {
// cc users mentioned in last comment
Change lastChange = ticket.changes.get(ticket.changes.size() - 1);
if (lastChange.hasComment()) {
Pattern p = Pattern.compile("\\s@([A-Za-z0-9-_]+)");
Pattern p = Pattern.compile(Constants.REGEX_TICKET_MENTION);
Matcher m = p.matcher(lastChange.comment.text);
while (m.find()) {
String username = m.group();
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/gitblit/utils/MarkdownUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.pegdown.PegDownProcessor;
import org.pegdown.ast.RootNode;

import com.gitblit.Constants;
import com.gitblit.IStoredSettings;
import com.gitblit.Keys;
import com.gitblit.wicket.MarkupProcessor.WorkaroundHtmlSerializer;
Expand Down Expand Up @@ -138,7 +139,7 @@ public static String transformGFM(IStoredSettings settings, String input, String

// emphasize and link mentions
String mentionReplacement = String.format(" **[@$1](%1s/user/$1)**", canonicalUrl);
text = text.replaceAll("\\s@([A-Za-z0-9-_]+)", mentionReplacement);
text = text.replaceAll(Constants.REGEX_TICKET_MENTION, mentionReplacement);

// link ticket refs
String ticketReplacement = MessageFormat.format("$1[#$2]({0}/tickets?r={1}&h=$2)$3", canonicalUrl, repositoryName);
Expand Down

0 comments on commit 0e4eebc

Please sign in to comment.