-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
fix(parsers.json_v2): Remove BOM before parsing #11926
Conversation
The file input will remove a bom from a file before attmepting to parse it. If a body has the bom it will fail to parse. fixes: influxdata#11916
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.
Looks good to me. Thanks for putting this up @powersj! Do we need this for all plugins, i.e. should we maybe move this to the JSON parser(s) instead?
This crossed my mind since we already have it in two spots now. I was slightly worried about breaking something, but it seems data with a BOM will just not work. I will push a new commit to do this for every parse. Any concerns about doing it that way? |
Download PR build artifacts for linux_amd64.tar.gz, darwin_amd64.tar.gz, and windows_amd64.zip. 📦 Click here to get additional PR build artifactsArtifact URLs |
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.
Looks good to me. Thanks @powersj! I think we should centralize this function, e.g. in internal
as we already have at least 4 users...
reader := strings.NewReader(string(input)) | ||
body, _ := utfbom.Skip(reader) | ||
input, err := io.ReadAll(body) |
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.
Can we please make this an internal
function? We trim BOMs in inputs.file
, inputs.tail
, tools/custom_builder
and last but not least config/config.go
(trimBOM()
) and I guess we should use this new function in all those places (later).
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.
It would be useful to have this in telegraf shared code (like internal) but we could merge this first and factor it out into internal in a follow-up PR.
(cherry picked from commit 7c1d175)
The file input will remove a bom from a file before attempting to parse it. If a body has the bom it will fail to parse.
fixes: #11916