summaryrefslogtreecommitdiffstats
path: root/modules/charset/charset.go
diff options
context:
space:
mode:
Diffstat (limited to 'modules/charset/charset.go')
-rw-r--r--modules/charset/charset.go5
1 files changed, 3 insertions, 2 deletions
diff --git a/modules/charset/charset.go b/modules/charset/charset.go
index 47906e2638..ae5cf5aa1a 100644
--- a/modules/charset/charset.go
+++ b/modules/charset/charset.go
@@ -13,6 +13,7 @@ import (
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
+ "code.gitea.io/gitea/modules/util"
"github.com/gogs/chardet"
"golang.org/x/net/html/charset"
@@ -25,9 +26,9 @@ var UTF8BOM = []byte{'\xef', '\xbb', '\xbf'}
// ToUTF8WithFallbackReader detects the encoding of content and coverts to UTF-8 reader if possible
func ToUTF8WithFallbackReader(rd io.Reader) io.Reader {
var buf = make([]byte, 2048)
- n, err := rd.Read(buf)
+ n, err := util.ReadAtMost(rd, buf)
if err != nil {
- return rd
+ return io.MultiReader(bytes.NewReader(RemoveBOMIfPresent(buf[:n])), rd)
}
charsetLabel, err := DetectEncoding(buf[:n])