diff --git a/modules/markup/html.go b/modules/markup/html.go index 2fe0caa5b6..0ac0463493 100644 --- a/modules/markup/html.go +++ b/modules/markup/html.go @@ -49,7 +49,7 @@ var ( // hashCurrentPattern matches string that represents a commit SHA, e.g. d8a994ef243349f321568f9e36d5c3f444b99cae // Although SHA1 hashes are 40 chars long, SHA256 are 64, the regex matches the hash from 7 to 64 chars in length // so that abbreviated hash links can be used as well. This matches git and GitHub usability. - hashCurrentPattern = regexp.MustCompile(`(?:^|\s)[^\w\d]{0,2}([0-9a-f]{7,64})[^\w\d]{0,2}(?:\s|$)`) + hashCurrentPattern = regexp.MustCompile(`(?:^|\s)[^\w\d]*([0-9a-f]{7,64})[^\w\d]*(?:\s|$)`) // shortLinkPattern matches short but difficult to parse [[name|link|arg=test]] syntax shortLinkPattern = regexp.MustCompile(`\[\[(.*?)\]\](\w*)`) diff --git a/modules/markup/html_internal_test.go b/modules/markup/html_internal_test.go index 1f717a78ed..21572bdda3 100644 --- a/modules/markup/html_internal_test.go +++ b/modules/markup/html_internal_test.go @@ -475,6 +475,9 @@ func TestRegExp_hashCurrentPattern(t *testing.T) { ":abcd3ef", ".abcd3ef", " (abcd3ef). ", + "abcd3ef...", + "...abcd3ef", + "(!...abcd3ef", } falseTestCases := []string{ "test", @@ -484,6 +487,7 @@ func TestRegExp_hashCurrentPattern(t *testing.T) { "abcdefghijklmnopqrstuvwxyzabcdefghijklmO", "commit/abcdefd", "abcd3ef...defabcd", + "f..defabcd", } for _, testCase := range trueTestCases { diff --git a/modules/markup/html_test.go b/modules/markup/html_test.go index 512a7aa02a..6c6658748a 100644 --- a/modules/markup/html_test.go +++ b/modules/markup/html_test.go @@ -57,8 +57,10 @@ func TestRender_Commits(t *testing.T) { } sha := "65f1bf27bc3bf70f64657658635e66094edbcb4d" + shaWithExtra := "65f1bf27bc3bf70f64657658635e66094edbcb4d..." repo := markup.TestRepoURL commit := util.URLJoin(repo, "commit", sha) + commitWithExtra := util.URLJoin(repo, "commit", shaWithExtra) tree := util.URLJoin(repo, "tree", sha, "src") file := util.URLJoin(repo, "commit", sha, "example.txt") @@ -69,9 +71,11 @@ func TestRender_Commits(t *testing.T) { commitCompareWithHash := commitCompare + "#L2" test(sha, `
`) + test(shaWithExtra, `65f1bf27bc...
65f1bf27bc...