summaryrefslogtreecommitdiffstats
path: root/tpl
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-10-30 17:36:05 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-10-30 18:12:14 +0100
commit3a786a248d3eff6e732aa94e87d6e88196e5147a (patch)
tree8adae8d35ba7522cc91b0936bbbeb5888337b65d /tpl
parent729593c842794eaf7127050953a5c2256d332051 (diff)
tpl: Fix BOM issue in templates
Fixes #4895
Diffstat (limited to 'tpl')
-rw-r--r--tpl/tplimpl/template.go19
1 files changed, 18 insertions, 1 deletions
diff --git a/tpl/tplimpl/template.go b/tpl/tplimpl/template.go
index 8a26ce0e1..144bafdd8 100644
--- a/tpl/tplimpl/template.go
+++ b/tpl/tplimpl/template.go
@@ -655,6 +655,22 @@ func (t *textTemplates) handleMaster(name, overlayFilename, masterFilename strin
}
+func removeLeadingBOM(s string) string {
+ const bom = '\ufeff'
+
+ for i, r := range s {
+ if i == 0 && r != bom {
+ return s
+ }
+ if i > 0 {
+ return s[i:]
+ }
+ }
+
+ return s
+
+}
+
func (t *templateHandler) addTemplateFile(name, baseTemplatePath, path string) error {
t.checkState()
@@ -666,7 +682,8 @@ func (t *templateHandler) addTemplateFile(name, baseTemplatePath, path string) e
if err != nil {
return templateInfo{filename: filename, fs: fs}, err
}
- s := string(b)
+
+ s := removeLeadingBOM(string(b))
realFilename := filename
if fi, err := fs.Stat(filename); err == nil {