Skip to content

Remove utf-8 BOM when loading chart files and helmignore - #7972

Merged
mattfarina merged 2 commits into
helm:masterfrom
IppX:bug/6081-bom-in-resource-file
Apr 28, 2020
Merged

mattfarina merged 2 commits into
helm:masterfrom
IppX:bug/6081-bom-in-resource-file

Conversation

@IppX

@IppX IppX commented Apr 23, 2020 •

Copy link
Copy Markdown
Contributor

Closes #6081

Removes the BOM prefix if present, in read files before processing the data.
Affects the following pkg:

  • pkg/chart/loader: directory and archive loader
  • internal/ignore: when loading .helmignore file

It's my first contribution and I'm no golang expert please be gentle :).

I initially tried another solution with BOMOverride to also handle UTF-16 BOM but it broke other parts that I did not understand.

Also let me know if I need to backport this to v2.x.

Removes the BOM prefix if present, in read files before
processing the data.
Affects the following pkg:
- pkg/chart/loader: directory and archive loader
- internal/ignore: when loading .helmignore file

Signed-off-by: Thomas FREYSS <[email protected]>
@helm-bot helm-bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Apr 23, 2020
@technosophos

Copy link
Copy Markdown
Member

Asking out of ignorance: Is there any case where a bare BOM might appear in the middle of a file, and legitimately so? For example, if a configmap has a field that contains a complete file, and that file for some reason needs the BOM.

I looked around a little, and I can't find information on this. My guess is that a BOM in the middle of a YAML doc is against the YAML spec. But I am not sure.

@mattfarina mattfarina left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get a test to verify the BOM is in the test chart? This is to make sure a change from someone does not accidentally remove it. We want to make sure the invisible characters are not accidentally dropped.

@IppX

IppX commented Apr 23, 2020

Copy link
Copy Markdown
Contributor Author

@technosophos
BOMs are not allowed in the middle unless they are in quotes, according to the spec (https://yaml.org/spec/1.2/spec.html#id2771184):

To make it easier to concatenate streams, byte order marks may appear at the start of any document. However all documents in the same stream must use the same character encoding.
To allow for JSON compatibility, byte order marks are also allowed inside quoted scalars. For readability, such content byte order marks should be escaped on output.

@IppX

IppX commented Apr 24, 2020

Copy link
Copy Markdown
Contributor Author

Can we get a test to verify the BOM is in the test chart? This is to make sure a change from someone does not accidentally remove it. We want to make sure the invisible characters are not accidentally dropped.

I added a test to check the presence of BOM in the test data beforehand. Is this what you were looking for ?

@technosophos

Copy link
Copy Markdown
Member

Based on @IppX 's last note from the YAML spec, I think this is good as-is. @mattfarina can you weigh in on the test you asked for? I was not totally clear what you were asking for there, but I think the new test addresses your concern.

@mattfarina mattfarina left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great. Thanks for adding the test. This will help us to not accidentally delete the BOMs in the test files.

@mattfarina mattfarina added this to the 3.3.0 milestone Apr 28, 2020
@mattfarina
mattfarina merged commit 2139e82 into helm:master Apr 28, 2020
@IppX

IppX commented Apr 30, 2020

Copy link
Copy Markdown
Contributor Author

Thanks for taking the time to review this !

@IppX
IppX deleted the bug/6081-bom-in-resource-file branch April 30, 2020 14:44
@hickeyma hickeyma added the needs-pick Indicates that a PR needs to be cherry-picked into the next release candidate. label May 8, 2020
@marckhouzam marckhouzam removed the needs-pick Indicates that a PR needs to be cherry-picked into the next release candidate. label Mar 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UTF-8 BOM in a resource template fails deployment

6 participants