Skip to content
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

replaceInFiles changes the Encoding UFT8 without BOM to UTF8 with BOM #2032

Closed
bsteinemann opened this issue Jul 23, 2018 · 1 comment
Closed

Comments

@bsteinemann
Copy link
Contributor

Description

I am using the method 'replaceInFiles' (Template.fs) to patch my configurations files. The files need to be encoded in UTF8 without BOM. When using replaceInFiles the encoding of the File is changed from UTF8 without BOM to UTF8 with BOM.

This happens because of the default encoding in the File-Module is UTF8.

Repro steps

  • create a file encoded with UTF8 without BOM
  • use the replaceInFiles to replace anything in the file

The encoding of the file is now UTF8 with BOM.

Expected behavior

Using replaceInFiles should not change the encoding of the file.

Suggested Solution

Since the methods in the File-Module use the method 'getEncoding' to detect the encoding of existing files and the encoding UTF8 with a BOM can be detected. The default encoding should be UTF8 without BOM. This would prevent a change of the file encoding of files encoded in UTF8 without BOM.

I am aware of the fact that this change could cause problems for other people if they are writing new files because the encoding of new Files would change to UTF8 without BOM.

Workaround

Rewriting the file with the encoding UTF8 without BOM after using 'replaceInFiles' solves the problem for me.

@matthid
Copy link
Member

matthid commented Jul 28, 2018

Yes I agree that replaceInFiles shouldn't change the existing encoding (just like other helpers don't by default). This is definitely a bugfix and a PR would be welcome and merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants