Fix UTF-8 in upper-case, use ansi charset for all non UTF-8 encodings

This commit is contained in:
Vladimir Vissoultchev 2015-07-29 17:58:03 +03:00
parent 4917d29c12
commit 2cc050e21e
3 changed files with 4 additions and 4 deletions

View File

@ -55,7 +55,7 @@ func ShortSha(sha1 string) string {
func DetectEncoding(content []byte) (string, error) { func DetectEncoding(content []byte) (string, error) {
detector := chardet.NewTextDetector() detector := chardet.NewTextDetector()
result, err := detector.DetectBest(content) result, err := detector.DetectBest(content)
if result.Charset == "ISO-8859-1" { if result.Charset != "UTF-8" && len(setting.AnsiCharset) > 0 {
return setting.AnsiCharset, err return setting.AnsiCharset, err
} }
return result.Charset, err return result.Charset, err
@ -67,7 +67,7 @@ func ToUtf8WithErr(content []byte) (error, string) {
return err, "" return err, ""
} }
if charsetLabel == "utf8" { if charsetLabel == "UTF-8" {
return nil, string(content) return nil, string(content)
} }

View File

@ -313,7 +313,7 @@ func NewConfigContext() {
RepoRootPath = path.Clean(RepoRootPath) RepoRootPath = path.Clean(RepoRootPath)
} }
ScriptType = sec.Key("SCRIPT_TYPE").MustString("bash") ScriptType = sec.Key("SCRIPT_TYPE").MustString("bash")
AnsiCharset = sec.Key("ANSI_CHARSET").MustString("ISO-8859-1") AnsiCharset = sec.Key("ANSI_CHARSET").MustString("")
// UI settings. // UI settings.
IssuePagingNum = Cfg.Section("ui").Key("ISSUE_PAGING_NUM").MustInt(10) IssuePagingNum = Cfg.Section("ui").Key("ISSUE_PAGING_NUM").MustInt(10)

View File

@ -28,7 +28,7 @@ func ServeBlob(ctx *middleware.Context, blob *git.Blob) error {
_, isTextFile := base.IsTextFile(buf) _, isTextFile := base.IsTextFile(buf)
if isTextFile { if isTextFile {
charset, _ := base.DetectEncoding(buf) charset, _ := base.DetectEncoding(buf)
if charset != "utf-8" { if charset != "UTF-8" {
ctx.Resp.Header().Set("Content-Type", "text/plain; charset="+charset) ctx.Resp.Header().Set("Content-Type", "text/plain; charset="+charset)
} }
} else { } else {