summaryrefslogtreecommitdiffstats
path: root/modules/base
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2015-12-13 19:56:33 -0500
committerUnknwon <u@gogs.io>2015-12-13 19:56:33 -0500
commit95f9c85bcc8f915d823f57cd5923302dfc156504 (patch)
treef6e74391810f4105f8b9712796df7f030b45095a /modules/base
parent79dcd7ee6e0c3bb576cf5d0ece583156c4466b95 (diff)
downloadgitea-95f9c85bcc8f915d823f57cd5923302dfc156504.tar.gz
gitea-95f9c85bcc8f915d823f57cd5923302dfc156504.zip
#2185 use Go sub-repo to detect encoding
Diffstat (limited to 'modules/base')
-rw-r--r--modules/base/tool.go13
1 files changed, 4 insertions, 9 deletions
diff --git a/modules/base/tool.go b/modules/base/tool.go
index b1d945117c..46eeca9b2b 100644
--- a/modules/base/tool.go
+++ b/modules/base/tool.go
@@ -22,8 +22,7 @@ import (
"github.com/Unknwon/com"
"github.com/Unknwon/i18n"
"github.com/microcosm-cc/bluemonday"
-
- "github.com/gogits/chardet"
+ "golang.org/x/net/html/charset"
"github.com/gogits/gogs/modules/avatar"
"github.com/gogits/gogs/modules/setting"
@@ -52,13 +51,9 @@ func ShortSha(sha1 string) string {
return sha1
}
-func DetectEncoding(content []byte) (string, error) {
- detector := chardet.NewTextDetector()
- result, err := detector.DetectBest(content)
- if result.Charset != "UTF-8" && len(setting.Repository.AnsiCharset) > 0 {
- return setting.Repository.AnsiCharset, err
- }
- return result.Charset, err
+func DetectEncoding(content []byte) string {
+ _, name, _ := charset.DetermineEncoding(content, setting.Repository.AnsiCharset)
+ return name
}
func BasicAuthDecode(encoded string) (string, string, error) {