diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/markup/html.go | 12 | ||||
-rw-r--r-- | modules/references/references.go | 4 | ||||
-rw-r--r-- | modules/references/references_test.go | 2 |
3 files changed, 12 insertions, 6 deletions
diff --git a/modules/markup/html.go b/modules/markup/html.go index 586343fae1..7ac23d0503 100644 --- a/modules/markup/html.go +++ b/modules/markup/html.go @@ -596,11 +596,15 @@ func mentionProcessor(ctx *postProcessCtx, node *html.Node) { mention := node.Data[loc.Start:loc.End] var teams string teams, ok := ctx.metas["teams"] - if ok && strings.Contains(teams, ","+strings.ToLower(mention[1:])+",") { - replaceContent(node, loc.Start, loc.End, createLink(util.URLJoin(setting.AppURL, "org", ctx.metas["org"], "teams", mention[1:]), mention, "mention")) - } else { - replaceContent(node, loc.Start, loc.End, createLink(util.URLJoin(setting.AppURL, mention[1:]), mention, "mention")) + // team mention should follow @orgName/teamName style + if ok && strings.Contains(mention, "/") { + mentionOrgAndTeam := strings.Split(mention, "/") + if mentionOrgAndTeam[0][1:] == ctx.metas["org"] && strings.Contains(teams, ","+strings.ToLower(mentionOrgAndTeam[1])+",") { + replaceContent(node, loc.Start, loc.End, createLink(util.URLJoin(setting.AppURL, "org", ctx.metas["org"], "teams", mentionOrgAndTeam[1]), mention, "mention")) + } + return } + replaceContent(node, loc.Start, loc.End, createLink(util.URLJoin(setting.AppURL, mention[1:]), mention, "mention")) } func shortLinkProcessor(ctx *postProcessCtx, node *html.Node) { diff --git a/modules/references/references.go b/modules/references/references.go index 6e0baefc6e..c243f25f5d 100644 --- a/modules/references/references.go +++ b/modules/references/references.go @@ -26,8 +26,8 @@ var ( // While fast, this is also incorrect and lead to false positives. // TODO: fix invalid linking issue - // mentionPattern matches all mentions in the form of "@user" - mentionPattern = regexp.MustCompile(`(?:\s|^|\(|\[)(@[0-9a-zA-Z-_]+|@[0-9a-zA-Z-_][0-9a-zA-Z-_.]+[0-9a-zA-Z-_])(?:\s|[:,;.?!]\s|[:,;.?!]?$|\)|\])`) + // mentionPattern matches all mentions in the form of "@user" or "@org/team" + mentionPattern = regexp.MustCompile(`(?:\s|^|\(|\[)(@[0-9a-zA-Z-_]+|@[0-9a-zA-Z-_]+\/?[0-9a-zA-Z-_]+|@[0-9a-zA-Z-_][0-9a-zA-Z-_.]+\/?[0-9a-zA-Z-_.]+[0-9a-zA-Z-_])(?:\s|[:,;.?!]\s|[:,;.?!]?$|\)|\])`) // issueNumericPattern matches string that references to a numeric issue, e.g. #1287 issueNumericPattern = regexp.MustCompile(`(?:\s|^|\(|\[)([#!][0-9]+)(?:\s|$|\)|\]|[:;,.?!]\s|[:;,.?!]$)`) // issueAlphanumericPattern matches string that references to an alphanumeric issue, e.g. ABC-1234 diff --git a/modules/references/references_test.go b/modules/references/references_test.go index f51379e4c3..d4f080490d 100644 --- a/modules/references/references_test.go +++ b/modules/references/references_test.go @@ -325,6 +325,7 @@ func TestRegExp_mentionPattern(t *testing.T) { {"@gitea.", "@gitea"}, {"@gitea,", "@gitea"}, {"@gitea;", "@gitea"}, + {"@gitea/team1;", "@gitea/team1"}, } falseTestCases := []string{ "@ 0", @@ -340,6 +341,7 @@ func TestRegExp_mentionPattern(t *testing.T) { "@gitea?this", "@gitea,this", "@gitea;this", + "@gitea/team1/more", } for _, testCase := range trueTestCases { |