Skip to content

Commit 4a46613

Browse files
committed
markdown: fix treating pure number as SHA1
- Detect non-exist commit and return 404 not 500
1 parent 6c8fcb3 commit 4a46613

File tree

5 files changed

+13
-4
lines changed

5 files changed

+13
-4
lines changed

.gopmfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ github.com/go-xorm/core = commit:5bf745d
1818
github.com/go-xorm/xorm = commit:c6c7056
1919
github.com/gogits/chardet = commit:2404f77
2020
github.com/gogits/cron = commit:7f3990a
21-
github.com/gogits/git-module = commit:31d8d73
21+
github.com/gogits/git-module = commit:2a820b5
2222
github.com/gogits/go-gogs-client = commit:e363d3f
2323
github.com/issue9/identicon = commit:d36b545
2424
github.com/jaytaylor/html2text = commit:52d9b78

cmd/web.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func checkVersion() {
8888
{"github.com/go-macaron/toolbox", toolbox.Version, "0.1.0"},
8989
{"gopkg.in/ini.v1", ini.Version, "1.8.4"},
9090
{"gopkg.in/macaron.v1", macaron.Version, "1.1.7"},
91-
{"github.com/gogits/git-module", git.Version, "0.3.5"},
91+
{"github.com/gogits/git-module", git.Version, "0.3.6"},
9292
{"github.com/gogits/go-gogs-client", gogs.Version, "0.12.0"},
9393
}
9494
for _, c := range checkers {

glide.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

modules/markdown/markdown.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ var (
9191
IssueAlphanumericPattern = regexp.MustCompile(`( |^|\()[A-Z]{1,10}-[1-9][0-9]*\b`)
9292

9393
// Sha1CurrentPattern matches string that represents a commit SHA, e.g. d8a994ef243349f321568f9e36d5c3f444b99cae
94+
// FIXME: this pattern matches pure numbers as well, right now we do a hack to check in RenderSha1CurrentPattern
95+
// by converting string to a number.
9496
Sha1CurrentPattern = regexp.MustCompile(`\b[0-9a-f]{7,40}\b`)
9597
)
9698

@@ -262,6 +264,9 @@ func RenderIssueIndexPattern(rawBytes []byte, urlPrefix string, metas map[string
262264
// RenderSha1CurrentPattern renders SHA1 strings to corresponding links that assumes in the same repository.
263265
func RenderSha1CurrentPattern(rawBytes []byte, urlPrefix string) []byte {
264266
return []byte(Sha1CurrentPattern.ReplaceAllStringFunc(string(rawBytes[:]), func(m string) string {
267+
if com.StrTo(m).MustInt() > 0 {
268+
return m
269+
}
265270
return fmt.Sprintf(`<a href="%s/commit/%s"><code>%s</code></a>`, urlPrefix, m, base.ShortSha(string(m)))
266271
}))
267272
}

routers/repo/commit.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,11 @@ func Diff(ctx *context.Context) {
152152

153153
commit, err := ctx.Repo.GitRepo.GetCommit(commitID)
154154
if err != nil {
155-
ctx.Handle(500, "Repo.GitRepo.GetCommit", err)
155+
if git.IsErrNotExist(err) {
156+
ctx.Handle(404, "Repo.GitRepo.GetCommit", err)
157+
} else {
158+
ctx.Handle(500, "Repo.GitRepo.GetCommit", err)
159+
}
156160
return
157161
}
158162

0 commit comments

Comments
 (0)