aboutsummaryrefslogtreecommitdiff
path: root/pkg/markup/sanitizer.go
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2017-04-05 13:12:05 -0400
committerUnknwon <u@gogs.io>2017-04-05 13:12:05 -0400
commit63598688e454274da53fea1d072d60dd0e783c4b (patch)
treed013459c79f3859b2d77fcc5cca6c2a4ba29bb87 /pkg/markup/sanitizer.go
parent497cdc925037e8a9172c7b2834790b587865fa9a (diff)
pkg/markup: init default sanitizer.policy
App would panic if user has validation error on installation and the sanitizer is not yet built. Therefore we need a minimal valid object for sanitizer at start.
Diffstat (limited to 'pkg/markup/sanitizer.go')
-rw-r--r--pkg/markup/sanitizer.go5
1 files changed, 3 insertions, 2 deletions
diff --git a/pkg/markup/sanitizer.go b/pkg/markup/sanitizer.go
index 63ead6df..39dcff66 100644
--- a/pkg/markup/sanitizer.go
+++ b/pkg/markup/sanitizer.go
@@ -20,14 +20,15 @@ type Sanitizer struct {
init sync.Once
}
-var sanitizer = &Sanitizer{}
+var sanitizer = &Sanitizer{
+ policy: bluemonday.UGCPolicy(),
+}
// NewSanitizer initializes sanitizer with allowed attributes based on settings.
// Multiple calls to this function will only create one instance of Sanitizer during
// entire application lifecycle.
func NewSanitizer() {
sanitizer.init.Do(func() {
- sanitizer.policy = bluemonday.UGCPolicy()
// We only want to allow HighlightJS specific classes for code blocks
sanitizer.policy.AllowAttrs("class").Matching(regexp.MustCompile(`^language-\w+$`)).OnElements("code")