mirror of
				https://github.com/go-gitea/gitea
				synced 2025-10-30 10:58:27 +00:00 
			
		
		
		
	markdown: fix treating pure number as SHA1
- Detect non-exist commit and return 404 not 500
This commit is contained in:
		| @@ -18,7 +18,7 @@ github.com/go-xorm/core = commit:5bf745d | ||||
| github.com/go-xorm/xorm = commit:c6c7056 | ||||
| github.com/gogits/chardet = commit:2404f77 | ||||
| github.com/gogits/cron = commit:7f3990a | ||||
| github.com/gogits/git-module = commit:31d8d73 | ||||
| github.com/gogits/git-module = commit:2a820b5 | ||||
| github.com/gogits/go-gogs-client = commit:e363d3f | ||||
| github.com/issue9/identicon = commit:d36b545 | ||||
| github.com/jaytaylor/html2text = commit:52d9b78 | ||||
|   | ||||
| @@ -88,7 +88,7 @@ func checkVersion() { | ||||
| 		{"github.com/go-macaron/toolbox", toolbox.Version, "0.1.0"}, | ||||
| 		{"gopkg.in/ini.v1", ini.Version, "1.8.4"}, | ||||
| 		{"gopkg.in/macaron.v1", macaron.Version, "1.1.7"}, | ||||
| 		{"github.com/gogits/git-module", git.Version, "0.3.5"}, | ||||
| 		{"github.com/gogits/git-module", git.Version, "0.3.6"}, | ||||
| 		{"github.com/gogits/go-gogs-client", gogs.Version, "0.12.0"}, | ||||
| 	} | ||||
| 	for _, c := range checkers { | ||||
|   | ||||
							
								
								
									
										2
									
								
								glide.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										2
									
								
								glide.lock
									
									
									
										generated
									
									
									
								
							| @@ -41,7 +41,7 @@ imports: | ||||
| - name: github.com/gogits/cron | ||||
|   version: 7f3990acf1833faa5ebd0e86f0a4c72a4b5eba3c | ||||
| - name: github.com/gogits/git-module | ||||
|   version: 31d8d73910d6f9ccb94ba6c17bbd18b1d01492ee | ||||
|   version: 2a820b5471795de4c8b993e15b0ed08155090c6a | ||||
| - name: github.com/gogits/go-gogs-client | ||||
|   version: e363d3ff8f70d0fe813324eedf228684af41c29c | ||||
| - name: github.com/issue9/identicon | ||||
|   | ||||
| @@ -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))) | ||||
| 	})) | ||||
| } | ||||
|   | ||||
| @@ -152,7 +152,11 @@ func Diff(ctx *context.Context) { | ||||
|  | ||||
| 	commit, err := ctx.Repo.GitRepo.GetCommit(commitID) | ||||
| 	if err != nil { | ||||
| 		ctx.Handle(500, "Repo.GitRepo.GetCommit", err) | ||||
| 		if git.IsErrNotExist(err) { | ||||
| 			ctx.Handle(404, "Repo.GitRepo.GetCommit", err) | ||||
| 		} else { | ||||
| 			ctx.Handle(500, "Repo.GitRepo.GetCommit", err) | ||||
| 		} | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user