Skip to content

Commit

Permalink
Trim BOM from config file for windows support
Browse files Browse the repository at this point in the history
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 influxdata/telegraf#1378
and http://utf8everywhere.org/#faq.boms
  • Loading branch information
sparrc committed Jun 24, 2016
1 parent b8e52ce commit a98712f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions cmd/influxd/run/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package run

import (
"bytes"
"fmt"
"io/ioutil"
"log"
Expand Down Expand Up @@ -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, "\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))
}

Expand Down

0 comments on commit a98712f

Please sign in to comment.