summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosef Fröhle <github@josef-froehle.de>2021-07-15 22:33:56 +0200
committerGitHub <noreply@github.com>2021-07-15 22:33:56 +0200
commit8d962daed6a51cefa18891a8b7c82847b0de5571 (patch)
tree13834a7042cbc62629ba2c0a344fe2d63c49731f
parentd7ee5dc7752c26b09edb8517c0e93a7b94b0fdb3 (diff)
downloadgitea-8d962daed6a51cefa18891a8b7c82847b0de5571.tar.gz
gitea-8d962daed6a51cefa18891a8b7c82847b0de5571.zip
cleanup code `issueFullPattern` in modules/markup (#16419)
fix #16415
-rw-r--r--modules/markup/html.go15
-rw-r--r--modules/markup/renderer.go1
2 files changed, 9 insertions, 7 deletions
diff --git a/modules/markup/html.go b/modules/markup/html.go
index 6d0b4fbea2..5ddd478ed6 100644
--- a/modules/markup/html.go
+++ b/modules/markup/html.go
@@ -13,6 +13,7 @@ import (
"path/filepath"
"regexp"
"strings"
+ "sync"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/emoji"
@@ -71,9 +72,6 @@ var (
// CSS class for action keywords (e.g. "closes: #1")
const keywordClass = "issue-keyword"
-// regexp for full links to issues/pulls
-var issueFullPattern *regexp.Regexp
-
// IsLink reports whether link fits valid format.
func IsLink(link []byte) bool {
return isLink(link)
@@ -88,12 +86,17 @@ func isLinkStr(link string) bool {
return validLinksPattern.MatchString(link)
}
-// FIXME: This function is not concurrent safe
+// regexp for full links to issues/pulls
+var issueFullPattern *regexp.Regexp
+
+// Once for to prevent races
+var issueFullPatternOnce sync.Once
+
func getIssueFullPattern() *regexp.Regexp {
- if issueFullPattern == nil {
+ issueFullPatternOnce.Do(func() {
issueFullPattern = regexp.MustCompile(regexp.QuoteMeta(setting.AppURL) +
`\w+/\w+/(?:issues|pulls)/((?:\w{1,10}-)?[1-9][0-9]*)([\?|#]\S+.(\S+)?)?\b`)
- }
+ })
return issueFullPattern
}
diff --git a/modules/markup/renderer.go b/modules/markup/renderer.go
index 04619caee3..3cd7cea700 100644
--- a/modules/markup/renderer.go
+++ b/modules/markup/renderer.go
@@ -19,7 +19,6 @@ import (
// Init initialize regexps for markdown parsing
func Init() {
- getIssueFullPattern()
NewSanitizer()
if len(setting.Markdown.CustomURLSchemes) > 0 {
CustomLinkURLSchemes(setting.Markdown.CustomURLSchemes)