diff options
author | Unknwon <u@gogs.io> | 2015-12-27 17:02:36 -0500 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2015-12-27 17:02:36 -0500 |
commit | 44637f03ccef3f005da41da5d1880df80cceebb2 (patch) | |
tree | 7cc21d72a5a08e0694d0c5571b378c63498fa39c /modules/template | |
parent | 240fe07287564be8c31e412b68350060b4c049d4 (diff) | |
download | gitea-44637f03ccef3f005da41da5d1880df80cceebb2.tar.gz gitea-44637f03ccef3f005da41da5d1880df80cceebb2.zip |
#2282 fast detection of utf-8
Diffstat (limited to 'modules/template')
-rw-r--r-- | modules/template/template.go | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/modules/template/template.go b/modules/template/template.go index 4149de451a..6c070b7009 100644 --- a/modules/template/template.go +++ b/modules/template/template.go @@ -12,7 +12,6 @@ import ( "runtime" "strings" "time" - "unicode/utf8" "golang.org/x/net/html/charset" "golang.org/x/text/transform" @@ -131,11 +130,11 @@ func Sha1(str string) string { } func ToUtf8WithErr(content []byte) (error, string) { - if utf8.Valid(content[:1024]) { + charsetLabel := base.DetectEncoding(content) + if charsetLabel == "utf-8" { return nil, string(content) } - charsetLabel := base.DetectEncoding(content) encoding, _ := charset.Lookup(charsetLabel) if encoding == nil { return fmt.Errorf("Unknown encoding: %s", charsetLabel), string(content) |