Modules icon indicating copy to clipboard operation
Modules copied to clipboard

Remove UTF-8 BOM from text files (except PowerShell files)

Open xtqqczze opened this issue 4 years ago • 8 comments

See also: PowerShell/PowerShell#11546

xtqqczze avatar Aug 29 '20 18:08 xtqqczze

Probably best not to remove the BOM from PowerShell scripts. Any script that needs to be run by Windows PowerShell needs a BOM so that WinPS won't try to read it as CP-1252

rjmholt avatar Aug 29 '20 19:08 rjmholt

@rjmholt The changed *.ps1, *.psd1 scripts are ASCII-safe. A good point that Windows PowerShell defaults to Windows-1252 though. [1]

xtqqczze avatar Aug 29 '20 21:08 xtqqczze

[1]

Ha, yes, despite the attributions at the top, I wrote that doc

The changed *.ps1, *.psd1 scripts are ASCII-safe

Yes, they are for now, but the issue arises when people edit them

rjmholt avatar Aug 30 '20 01:08 rjmholt

This repo contains 13 .ps1 files and 14 psd1 files, and 4 psm1 files. Currently only 2 of these files contain the BOM - I will exclude these from this PR.

Maybe we need to consider adding a BOM to the remaining PowerShell files. Alternatively, we could add a test to ensure all PowerShell files are ASCII-safe.

xtqqczze avatar Aug 30 '20 02:08 xtqqczze

Maybe we need to consider adding a BOM to the remaining PowerShell files. Alternatively, we could add a test to ensure all PowerShell files are ASCII-safe.

Yeah, it sounds like adding the BOM would be a good idea. PSScriptAnalyzer exports this rule to assess scripts' need for a BOM.

rjmholt avatar Aug 31 '20 17:08 rjmholt

Ah, so that's the purpose of UseBOMForUnicodeEncodedFile 😄

xtqqczze avatar Aug 31 '20 18:08 xtqqczze

I think the best approach would be to check the PowerShell files are ASCII-safe with a Github action. However, in the short term, the simplest solution seems to be just to add the BOM to these files.

xtqqczze avatar Aug 31 '20 23:08 xtqqczze

@rjmholt This PR is ready for review.

xtqqczze avatar Aug 31 '20 23:08 xtqqczze