summaryrefslogtreecommitdiffstats
path: root/modules/templates/helper.go
diff options
context:
space:
mode:
Diffstat (limited to 'modules/templates/helper.go')
-rw-r--r--modules/templates/helper.go14
1 files changed, 8 insertions, 6 deletions
diff --git a/modules/templates/helper.go b/modules/templates/helper.go
index d3eb8c48b8..b6c5cc5945 100644
--- a/modules/templates/helper.go
+++ b/modules/templates/helper.go
@@ -267,7 +267,7 @@ func ToUTF8WithErr(content []byte) (string, error) {
if err != nil {
return "", err
} else if charsetLabel == "UTF-8" {
- return string(content), nil
+ return string(base.RemoveBOMIfPresent(content)), nil
}
encoding, _ := charset.Lookup(charsetLabel)
@@ -277,19 +277,21 @@ func ToUTF8WithErr(content []byte) (string, error) {
// If there is an error, we concatenate the nicely decoded part and the
// original left over. This way we won't lose data.
- result, n, err := transform.String(encoding.NewDecoder(), string(content))
+ result, n, err := transform.Bytes(encoding.NewDecoder(), content)
if err != nil {
- result = result + string(content[n:])
+ result = append(result, content[n:]...)
}
- return result, err
+ result = base.RemoveBOMIfPresent(result)
+
+ return string(result), err
}
// ToUTF8WithFallback detects the encoding of content and coverts to UTF-8 if possible
func ToUTF8WithFallback(content []byte) []byte {
charsetLabel, err := base.DetectEncoding(content)
if err != nil || charsetLabel == "UTF-8" {
- return content
+ return base.RemoveBOMIfPresent(content)
}
encoding, _ := charset.Lookup(charsetLabel)
@@ -304,7 +306,7 @@ func ToUTF8WithFallback(content []byte) []byte {
return append(result, content[n:]...)
}
- return result
+ return base.RemoveBOMIfPresent(result)
}
// ToUTF8 converts content to UTF8 encoding and ignore error