Skip to content

Commit 6bcff78

Browse files
DblKunknwon
authored andcommitted
Fix mention in comments like (@DblK) (#3655)
* Fix mention in comments like (@DblK) * Better fix to avoid making link for "Hello@DblK"
1 parent 2cb5ec5 commit 6bcff78

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

modules/markdown/markdown.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func IsReadmeFile(name string) bool {
7676

7777
var (
7878
// MentionPattern matches string that mentions someone, e.g. @Unknwon
79-
MentionPattern = regexp.MustCompile(`(\s|^)@[0-9a-zA-Z-_\.]+`)
79+
MentionPattern = regexp.MustCompile(`(\s|^|\W)@[0-9a-zA-Z-_\.]+`)
8080

8181
// CommitPattern matches link to certain commit with or without trailing hash,
8282
// e.g. https://try.gogs.io/gogs/gogs/commit/d8a994ef243349f321568f9e36d5c3f444b99cae#diff-2
@@ -101,7 +101,7 @@ var (
101101
func FindAllMentions(content string) []string {
102102
mentions := MentionPattern.FindAllString(content, -1)
103103
for i := range mentions {
104-
mentions[i] = strings.TrimSpace(mentions[i])[1:] // Strip @ character
104+
mentions[i] = mentions[i][strings.Index(mentions[i], "@")+1:] // Strip @ character
105105
}
106106
return mentions
107107
}
@@ -275,7 +275,7 @@ func RenderSha1CurrentPattern(rawBytes []byte, urlPrefix string) []byte {
275275
func RenderSpecialLink(rawBytes []byte, urlPrefix string, metas map[string]string) []byte {
276276
ms := MentionPattern.FindAll(rawBytes, -1)
277277
for _, m := range ms {
278-
m = bytes.TrimSpace(m)
278+
m = m[bytes.Index(m, []byte("@")):]
279279
rawBytes = bytes.Replace(rawBytes, m,
280280
[]byte(fmt.Sprintf(`<a href="%s/%s">%s</a>`, setting.AppSubUrl, m[1:], m)), -1)
281281
}

0 commit comments

Comments
 (0)