Fix #3420: Bad commit URL generation (#3424)

This commit is contained in:
Thibault Meyer 2016-08-10 20:35:06 +02:00 committed by 无闻
parent 8ad92bb8a4
commit 99812a80fd

View File

@ -260,12 +260,9 @@ func RenderIssueIndexPattern(rawBytes []byte, urlPrefix string, metas map[string
// RenderSha1CurrentPattern renders SHA1 strings to corresponding links that assumes in the same repository.
func RenderSha1CurrentPattern(rawBytes []byte, urlPrefix string) []byte {
ms := Sha1CurrentPattern.FindAll(rawBytes, -1)
for _, m := range ms {
rawBytes = bytes.Replace(rawBytes, m, []byte(fmt.Sprintf(
`<a href="%s/commit/%s"><code>%s</code></a>`, urlPrefix, m, base.ShortSha(string(m)))), -1)
}
return rawBytes
return []byte(Sha1CurrentPattern.ReplaceAllStringFunc(string(rawBytes[:]), func(m string) string {
return fmt.Sprintf(`<a href="%s/commit/%s"><code>%s</code></a>`, urlPrefix, m, base.ShortSha(string(m)))
}))
}
// RenderSpecialLink renders mentions, indexes and SHA1 strings to corresponding links.