-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trim BOM from config file for windows support #6900
Conversation
By analyzing the blame information on this pull request, we identified @gunnaraasen and @e-dard to be potential reviewers |
without this change we get an error when parsing a file with a BOM:
|
corresponding PR in telegraf: influxdata/telegraf#1404 |
cc @nathanielc in case you want to make this change for Kapacitor as well |
@sparrc I think it would be nice to keep these sort of OS-specific actions in the the OS binaries or runtimes. So I would prefer something in if runtime.GOOS != "windows" {
return fileBytes
} An alternative approach would to use build flags to compile out the |
That seems reasonable. Although one counterpoint is that the BOM is not necessarily only on Windows. Any editor/OS can add that prefix, but as far as I know Notepad is the only one that actually does. Also a file that Notepad saves could be transferred to any other machine. Vim, for example, deals with the BOM on any system. You can validly open a file with a BOM on linux/osx so we may want to do the same. |
Ah right OK. If it's not windows-specific then it's cool as it is. LGTM 👍 |
Update the changelog and I think this is good. I agree with @sparrc that we shouldn't limit this code to only Windows. It's possible for someone to edit a file in Notepad on Windows and then copy it to a Linux machine by using something like Chef or Ansible so I think it's worth always trimming the byte mark since it doesn't really harm the Linux version. |
7fe2e99
to
c7141b5
Compare
// this is for Windows compatability only. | ||
// see https://github.com/influxdata/telegraf/issues/1378 | ||
func trimBOM(f []byte) []byte { | ||
return bytes.Trim(f, "\xef\xbb\xbf") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should definitely be bytes.TrimPrefix
... bytes.Trim
will remove the code points from the beginning and the end. If this is only going to appear at the beginning, we should only check there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, I'll change it
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
Required for all non-trivial PRs
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