From 5233f5f3e538b9f64a9115e9a727c9005013a620 Mon Sep 17 00:00:00 2001 From: Giteabot Date: Thu, 13 Jun 2024 09:14:49 +0800 Subject: [PATCH] Fix hash render end with colon (#31319) (#31346) Backport #31319 by @lunny Fix a hash render problem like `: xxxxx` which is usually used in release notes. Co-authored-by: Lunny Xiao (cherry picked from commit 6ca70c5bf20fc6b3a7d98d784f48b5a503962339) --- modules/markup/html.go | 2 +- modules/markup/html_internal_test.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/markup/html.go b/modules/markup/html.go index 56f63b8a76..4c73b6d796 100644 --- a/modules/markup/html.go +++ b/modules/markup/html.go @@ -48,7 +48,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|^|\(|\[)([0-9a-f]{7,64})(?:\s|$|\)|\]|[.,](\s|$))`) + hashCurrentPattern = regexp.MustCompile(`(?:\s|^|\(|\[)([0-9a-f]{7,64})(?:\s|$|\)|\]|[.,:](\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 e313be7040..a9fd8c1be6 100644 --- a/modules/markup/html_internal_test.go +++ b/modules/markup/html_internal_test.go @@ -381,6 +381,7 @@ func TestRegExp_sha1CurrentPattern(t *testing.T) { "(abcdefabcdefabcdefabcdefabcdefabcdefabcd)", "[abcdefabcdefabcdefabcdefabcdefabcdefabcd]", "abcdefabcdefabcdefabcdefabcdefabcdefabcd.", + "abcdefabcdefabcdefabcdefabcdefabcdefabcd:", } falseTestCases := []string{ "test",