c572fcfe04
Rename the Go module path from code.gitea.io/gitea to git.mokoconsulting.tech/MokoConsulting/MokoGitea across the entire codebase. Scope: - go.mod module declaration - 2,235 Go source files (import paths) - Dockerfile WORKDIR and COPY paths - Swagger API templates - golangci.yml linter config External dependencies (code.gitea.io/gitea-vet, code.gitea.io/sdk/gitea, gitea.com/gitea/act, etc.) are intentionally NOT renamed — they are separate upstream modules. Closes #132 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
44 lines
1.4 KiB
Go
44 lines
1.4 KiB
Go
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package charset
|
|
|
|
import (
|
|
"html/template"
|
|
"io"
|
|
"strings"
|
|
|
|
"git.mokoconsulting.tech/MokoConsulting/MokoGitea/modules/setting"
|
|
"git.mokoconsulting.tech/MokoConsulting/MokoGitea/modules/translation"
|
|
)
|
|
|
|
type EscapeOptions struct {
|
|
Allowed map[rune]bool
|
|
}
|
|
|
|
func AllowRuneNBSP() map[rune]bool {
|
|
return map[rune]bool{0xa0: true}
|
|
}
|
|
|
|
func EscapeOptionsForView() EscapeOptions {
|
|
return EscapeOptions{
|
|
// it's safe to see NBSP in the view, but maybe not in the diff
|
|
Allowed: AllowRuneNBSP(),
|
|
}
|
|
}
|
|
|
|
// 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) {
|
|
if !setting.UI.AmbiguousUnicodeDetection {
|
|
return &EscapeStatus{}, html
|
|
}
|
|
sb := &strings.Builder{}
|
|
escaped, _ = EscapeControlReader(strings.NewReader(string(html)), sb, locale, opts...) // err has been handled in EscapeControlReader
|
|
return escaped, template.HTML(sb.String())
|
|
}
|
|
|
|
// 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...)
|
|
}
|