From 98360c50d51e523eaeaf811147bda82aa5b5cbdd Mon Sep 17 00:00:00 2001 From: Cameron Sparr Date: Thu, 23 Jun 2016 09:19:39 +0100 Subject: [PATCH] Trim BOM from config file for windows support Default windows text editor (Notepad) adds a BOM to the beginning of the file. This needs to be trimmed otherwise we will get an "invalid toml" error. see https://github.com/influxdata/telegraf/issues/1378 and http://utf8everywhere.org/#faq.boms --- CHANGELOG.md | 1 + cmd/influxd/run/config.go | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c8b0b71c6..f9fa8d70f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ With this release the systemd configuration files for InfluxDB will use the syst - [#6820](https://github.com/influxdata/influxdb/issues/6820): Add NodeID to execution options - [#4532](https://github.com/influxdata/influxdb/issues/4532): Support regex selection in SHOW TAG VALUES for the key. - [#6889](https://github.com/influxdata/influxdb/pull/6889): Update help and remove unused config options from the configuration file. +- [#6900](https://github.com/influxdata/influxdb/pull/6900): Trim BOM from Windows Notepad-saved config files. ### Bugfixes diff --git a/cmd/influxd/run/config.go b/cmd/influxd/run/config.go index 8da1e10d09..9a78b48b42 100644 --- a/cmd/influxd/run/config.go +++ b/cmd/influxd/run/config.go @@ -1,6 +1,7 @@ package run import ( + "bytes" "fmt" "io/ioutil" "log" @@ -110,12 +111,20 @@ func NewDemoConfig() (*Config, error) { return c, nil } +// trimBOM trims the Byte-Order-Marks from the beginning of the file. +// this is for Windows compatability only. +// see https://github.com/influxdata/telegraf/issues/1378 +func trimBOM(f []byte) []byte { + return bytes.TrimPrefix(f, []byte("\xef\xbb\xbf")) +} + // FromTomlFile loads the config from a TOML file. func (c *Config) FromTomlFile(fpath string) error { bs, err := ioutil.ReadFile(fpath) if err != nil { return err } + bs = trimBOM(bs) return c.FromToml(string(bs)) }