From 7eed11e5e9855324dd328a99133bf1f668076f80 Mon Sep 17 00:00:00 2001 From: Gary Kim Date: Wed, 14 Aug 2019 08:04:55 +0000 Subject: Check commit message hashes before making links (#7713) * Check commit message hashes before making links Previously, when formatting commit messages, anything that looked like SHA1 hashes was turned into a link using regex. This meant that certain phrases or numbers such as `777777` or `deadbeef` could be recognized as a commit even if the repository has no commit with those hashes. This change will make it so that anything that looks like a SHA1 hash using regex will then also be checked to ensure that there is a commit in the repository with that hash before making a link. Signed-off-by: Gary Kim * Use gogit to check if commit exists This commit modifies the commit hash check in the render for commit messages to use gogit for better performance. Signed-off-by: Gary Kim * Make code cleaner Signed-off-by: Gary Kim * Use rev-parse to check if commit exists Signed-off-by: Gary Kim * Add and modify tests for checking hashes in html link rendering Signed-off-by: Gary Kim * Return error in sha1CurrentPatternProcessor Co-Authored-By: mrsdizzie * Import Gitea log module Signed-off-by: Gary Kim * Revert "Return error in sha1CurrentPatternProcessor" This reverts commit 28f561cac46ef7e51aa26aefcbe9aca4671366a6. Signed-off-by: Gary Kim * Add debug logging to sha1CurrentPatternProcessor This will log errors by the git command run in sha1CurrentPatternProcessor if the error is one that was unexpected. Signed-off-by: Gary Kim --- modules/markup/markdown/markdown_test.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'modules/markup/markdown/markdown_test.go') diff --git a/modules/markup/markdown/markdown_test.go b/modules/markup/markdown/markdown_test.go index 92b4f03e34..669b49367e 100644 --- a/modules/markup/markdown/markdown_test.go +++ b/modules/markup/markdown/markdown_test.go @@ -21,8 +21,9 @@ const AppSubURL = AppURL + Repo + "/" // these values should match the Repo const above var localMetas = map[string]string{ - "user": "gogits", - "repo": "gogs", + "user": "gogits", + "repo": "gogs", + "repoPath": "../../../integrations/gitea-repositories-meta/user13/repo11.git/", } func TestRender_StandardLinks(t *testing.T) { @@ -103,7 +104,7 @@ func testAnswers(baseURLContent, baseURLImages string) []string {
  • Tips
  • -

    See commit fc7f44dadf

    +

    See commit 65f1bf27bc

    Ideas and codes

    @@ -194,7 +195,7 @@ var sameCases = []string{ - [[Links, Language bindings, Engine bindings|Links]] - [[Tips]] -See commit fc7f44dadf +See commit 65f1bf27bc Ideas and codes -- cgit v1.2.3