Skip to content

Commit

Permalink
Trim BOM from config file for windows support
Browse files Browse the repository at this point in the history
closes #1378
  • Loading branch information
sparrc committed Jun 22, 2016
1 parent 7825df4 commit 0075410
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,13 @@ func (c *Config) LoadConfig(path string) error {
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
// returns the AST produced from the TOML parser. When loading the file, it
// will find environment variables and replace them.
Expand All @@ -547,6 +554,8 @@ func parseFile(fpath string) (*ast.Table, error) {
if err != nil {
return nil, err
}
// ugh windows why
contents = trimBOM(contents)

env_vars := envVarRe.FindAll(contents, -1)
for _, env_var := range env_vars {
Expand Down

0 comments on commit 0075410

Please sign in to comment.