Trim BOM from config file for windows support

closes #1378
This commit is contained in:
Cameron Sparr 2016-06-22 18:54:29 +01:00
parent 50ea7f4a9d
commit 5ddd61d2e2
2 changed files with 10 additions and 0 deletions

View File

@ -37,6 +37,7 @@ should now look like:
- [#1384](https://github.com/influxdata/telegraf/pull/1384): Fix datarace in apache input plugin. - [#1384](https://github.com/influxdata/telegraf/pull/1384): Fix datarace in apache input plugin.
- [#1399](https://github.com/influxdata/telegraf/issues/1399): Add `read_repairs` statistics to riak plugin. - [#1399](https://github.com/influxdata/telegraf/issues/1399): Add `read_repairs` statistics to riak plugin.
- [#1405](https://github.com/influxdata/telegraf/issues/1405): Fix memory/connection leak in prometheus input plugin. - [#1405](https://github.com/influxdata/telegraf/issues/1405): Fix memory/connection leak in prometheus input plugin.
- [#1378](https://github.com/influxdata/telegraf/issues/1378): Trim BOM from config file for Windows support.
## v1.0 beta 2 [2016-06-21] ## v1.0 beta 2 [2016-06-21]

View File

@ -539,6 +539,13 @@ func (c *Config) LoadConfig(path string) error {
return nil return 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(fileBytes []byte) []byte {
return bytes.Trim(fileBytes, "\xef\xbb\xbf")
}
// parseFile loads a TOML configuration from a provided path and // parseFile loads a TOML configuration from a provided path and
// returns the AST produced from the TOML parser. When loading the file, it // returns the AST produced from the TOML parser. When loading the file, it
// will find environment variables and replace them. // will find environment variables and replace them.
@ -547,6 +554,8 @@ func parseFile(fpath string) (*ast.Table, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
// ugh windows why
contents = trimBOM(contents)
env_vars := envVarRe.FindAll(contents, -1) env_vars := envVarRe.FindAll(contents, -1)
for _, env_var := range env_vars { for _, env_var := range env_vars {