diff options
author | Unknwon <u@gogs.io> | 2016-08-15 15:27:19 -0700 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2016-08-15 15:27:19 -0700 |
commit | 4a46613916cdfa6a168746aba6abcd698cd17875 (patch) | |
tree | 0129f716668af004619b4cd7a937c0560d34ac0c /modules | |
parent | 6c8fcb3af252f6dfc76021b5acb10ac672dd8ca4 (diff) | |
download | gitea-4a46613916cdfa6a168746aba6abcd698cd17875.tar.gz gitea-4a46613916cdfa6a168746aba6abcd698cd17875.zip |
markdown: fix treating pure number as SHA1
- Detect non-exist commit and return 404 not 500
Diffstat (limited to 'modules')
-rw-r--r-- | modules/markdown/markdown.go | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/modules/markdown/markdown.go b/modules/markdown/markdown.go index a6cdf222e5..7bfb0ec60a 100644 --- a/modules/markdown/markdown.go +++ b/modules/markdown/markdown.go @@ -91,6 +91,8 @@ var ( IssueAlphanumericPattern = regexp.MustCompile(`( |^|\()[A-Z]{1,10}-[1-9][0-9]*\b`) // Sha1CurrentPattern matches string that represents a commit SHA, e.g. d8a994ef243349f321568f9e36d5c3f444b99cae + // FIXME: this pattern matches pure numbers as well, right now we do a hack to check in RenderSha1CurrentPattern + // by converting string to a number. Sha1CurrentPattern = regexp.MustCompile(`\b[0-9a-f]{7,40}\b`) ) @@ -262,6 +264,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 { return []byte(Sha1CurrentPattern.ReplaceAllStringFunc(string(rawBytes[:]), func(m string) string { + if com.StrTo(m).MustInt() > 0 { + return m + } return fmt.Sprintf(`<a href="%s/commit/%s"><code>%s</code></a>`, urlPrefix, m, base.ShortSha(string(m))) })) } |