summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRémy Boulanouar <rboulanouar@gmail.com>2016-10-17 04:17:59 +0200
committer无闻 <u@gogs.io>2016-10-16 22:17:59 -0400
commit6bcff7828f117af8d51285ce3acba01a7e40a867 (patch)
treef87c6187705d1c6cc73bb64e1cc867bda88d6cca
parent2cb5ec598388f5281e01e17e650421103b562b30 (diff)
downloadgitea-6bcff7828f117af8d51285ce3acba01a7e40a867.tar.gz
gitea-6bcff7828f117af8d51285ce3acba01a7e40a867.zip
Fix mention in comments like (@dblk) (#3655)v0.9.99
* Fix mention in comments like (@dblk) * Better fix to avoid making link for "Hello@DblK"
-rw-r--r--modules/markdown/markdown.go6
1 files changed, 3 insertions, 3 deletions
diff --git a/modules/markdown/markdown.go b/modules/markdown/markdown.go
index a15501ec8d..6724b248ad 100644
--- a/modules/markdown/markdown.go
+++ b/modules/markdown/markdown.go
@@ -76,7 +76,7 @@ func IsReadmeFile(name string) bool {
var (
// MentionPattern matches string that mentions someone, e.g. @Unknwon
- MentionPattern = regexp.MustCompile(`(\s|^)@[0-9a-zA-Z-_\.]+`)
+ MentionPattern = regexp.MustCompile(`(\s|^|\W)@[0-9a-zA-Z-_\.]+`)
// CommitPattern matches link to certain commit with or without trailing hash,
// e.g. https://try.gogs.io/gogs/gogs/commit/d8a994ef243349f321568f9e36d5c3f444b99cae#diff-2
@@ -101,7 +101,7 @@ var (
func FindAllMentions(content string) []string {
mentions := MentionPattern.FindAllString(content, -1)
for i := range mentions {
- mentions[i] = strings.TrimSpace(mentions[i])[1:] // Strip @ character
+ mentions[i] = mentions[i][strings.Index(mentions[i], "@")+1:] // Strip @ character
}
return mentions
}
@@ -275,7 +275,7 @@ func RenderSha1CurrentPattern(rawBytes []byte, urlPrefix string) []byte {
func RenderSpecialLink(rawBytes []byte, urlPrefix string, metas map[string]string) []byte {
ms := MentionPattern.FindAll(rawBytes, -1)
for _, m := range ms {
- m = bytes.TrimSpace(m)
+ m = m[bytes.Index(m, []byte("@")):]
rawBytes = bytes.Replace(rawBytes, m,
[]byte(fmt.Sprintf(`<a href="%s/%s">%s</a>`, setting.AppSubUrl, m[1:], m)), -1)
}