mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-18 02:43:25 +09:00
chore: fix various problems (#39298)
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
+12
-14
@@ -28,23 +28,21 @@ func EscapeOptionsForView() EscapeOptions {
|
||||
}
|
||||
}
|
||||
|
||||
func EscapeControlHTMLTo(html template.HTML, locale translation.Locale, w htmlutil.HTMLWriter, opts ...EscapeOptions) *EscapeStatus {
|
||||
if !setting.UI.AmbiguousUnicodeDetection {
|
||||
w.WriteHTML(html)
|
||||
return &EscapeStatus{}
|
||||
}
|
||||
escaped, _ := EscapeControlReader(strings.NewReader(string(html)), w.OriginWriter(), locale, opts...)
|
||||
return escaped
|
||||
}
|
||||
|
||||
// EscapeControlHTML escapes the Unicode control sequences in a provided html document
|
||||
func EscapeControlHTML(html template.HTML, locale translation.Locale, opts ...EscapeOptions) (escaped *EscapeStatus, output template.HTML) {
|
||||
sb, w := htmlutil.NewHTMLStringWriter()
|
||||
escaped = EscapeControlHTMLTo(html, locale, w, opts...)
|
||||
return escaped, template.HTML(sb.String())
|
||||
if !setting.UI.AmbiguousUnicodeDetection {
|
||||
return &EscapeStatus{}, html
|
||||
}
|
||||
w := &htmlutil.HTMLBuilder{}
|
||||
escaped, _ = EscapeControlReader(strings.NewReader(string(html)), w, locale, opts...)
|
||||
return escaped, w.HTMLString()
|
||||
}
|
||||
|
||||
// EscapeControlReader escapes the Unicode control sequences in a provided reader of HTML content and writer in a locale and returns the findings as an EscapeStatus
|
||||
func EscapeControlReader(reader io.Reader, writer io.Writer, locale translation.Locale, opts ...EscapeOptions) (*EscapeStatus, error) {
|
||||
return escapeStream(locale, reader, writer, opts...)
|
||||
func EscapeControlReader(reader io.Reader, writer htmlutil.HTMLWriter, locale translation.Locale, opts ...EscapeOptions) (*EscapeStatus, error) {
|
||||
if !setting.UI.AmbiguousUnicodeDetection {
|
||||
_, err := io.Copy(writer.OriginWriter(), reader)
|
||||
return &EscapeStatus{}, err
|
||||
}
|
||||
return escapeStream(locale, reader, writer.OriginWriter(), opts...)
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gitea.dev/modules/htmlutil"
|
||||
"gitea.dev/modules/setting"
|
||||
"gitea.dev/modules/test"
|
||||
"gitea.dev/modules/translation"
|
||||
@@ -145,7 +146,7 @@ then resh (ר), and finally heh (ה) (which should appear leftmost).`,
|
||||
func TestEscapeControlReader(t *testing.T) {
|
||||
for _, tt := range escapeControlTests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
output := &strings.Builder{}
|
||||
output := &htmlutil.HTMLBuilder{}
|
||||
status, err := EscapeControlReader(strings.NewReader(tt.text), output, &translation.MockLocale{})
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, tt.status, *status)
|
||||
|
||||
Reference in New Issue
Block a user