Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup code getIssueFullPattern in modules/markup #16419

Merged
merged 5 commits into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 9 additions & 6 deletions modules/markup/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"path/filepath"
"regexp"
"strings"
"sync"

"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/emoji"
Expand Down Expand Up @@ -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)
Expand All @@ -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
}

Expand Down
1 change: 0 additions & 1 deletion modules/markup/renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down