Skip to content

Refactor wiki #34805

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

Merged
merged 3 commits into from
Jun 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions modules/markup/sanitizer_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package markup

import (
"html/template"
"io"
"net/url"
"regexp"
Expand Down Expand Up @@ -92,9 +93,9 @@ func (st *Sanitizer) createDefaultPolicy() *bluemonday.Policy {
return policy
}

// Sanitize takes a string that contains a HTML fragment or document and applies policy whitelist.
func Sanitize(s string) string {
return GetDefaultSanitizer().defaultPolicy.Sanitize(s)
// Sanitize use default sanitizer policy to sanitize a string
func Sanitize(s string) template.HTML {
return template.HTML(GetDefaultSanitizer().defaultPolicy.Sanitize(s))
}

// SanitizeReader sanitizes a Reader
Expand Down
2 changes: 1 addition & 1 deletion modules/markup/sanitizer_default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ func TestSanitizer(t *testing.T) {
}

for i := 0; i < len(testCases); i += 2 {
assert.Equal(t, testCases[i+1], Sanitize(testCases[i]))
assert.Equal(t, testCases[i+1], string(Sanitize(testCases[i])))
}
}
4 changes: 2 additions & 2 deletions modules/templates/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ func safeHTML(s any) template.HTML {
panic(fmt.Sprintf("unexpected type %T", s))
}

// SanitizeHTML sanitizes the input by pre-defined markdown rules
// SanitizeHTML sanitizes the input by default sanitization rules.
func SanitizeHTML(s string) template.HTML {
return template.HTML(markup.Sanitize(s))
return markup.Sanitize(s)
}

func htmlEscape(s any) template.HTML {
Expand Down
Loading