Skip to content

Commit b7dcb8a

Browse files
authored
Use a BOM by default for Windows PowerShell's sake
Merge pull request #86 from PoshCode/feature/Utf8Bom +semver:fix
2 parents 5613497 + c1344c3 commit b7dcb8a

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

Source/Private/SetModuleContent.ps1

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function SetModuleContent {
2828

2929
# The encoding defaults to UTF8 (or UTF8NoBom on Core)
3030
[Parameter(DontShow)]
31-
[string]$Encoding = $(if($IsCoreCLR) { "UTF8NoBom" } else { "UTF8" })
31+
[string]$Encoding = $(if($IsCoreCLR) { "UTF8Bom" } else { "UTF8" })
3232
)
3333
begin {
3434
Push-Location $WorkingDirectory -StackName SetModuleContent
@@ -64,4 +64,4 @@ function SetModuleContent {
6464
$SetContent.End()
6565
Pop-Location -StackName SetModuleContent
6666
}
67-
}
67+
}

Source/Public/Build-Module.ps1

+4-4
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ function Build-Module {
110110

111111
# File encoding for output RootModule (defaults to UTF8)
112112
# Converted to System.Text.Encoding for PowerShell 6 (and something else for PowerShell 5)
113-
[ValidateSet("UTF8","UTF7","ASCII","Unicode","UTF32")]
114-
[string]$Encoding = "UTF8",
113+
[ValidateSet("UTF8", "UTF8Bom", "UTF8NoBom", "UTF7", "ASCII", "Unicode", "UTF32")]
114+
[string]$Encoding = $(if($IsCoreCLR) { "UTF8Bom" } else { "UTF8" }),
115115

116116
# The prefix is either the path to a file (relative to the module folder) or text to put at the top of the file.
117117
# If the value of prefix resolves to a file, that file will be read in, otherwise, the value will be used.
@@ -133,8 +133,8 @@ function Build-Module {
133133
)
134134

135135
begin {
136-
if ($Encoding -ne "UTF8") {
137-
Write-Warning "We strongly recommend you build your script modules with UTF8 encoding for maximum cross-platform compatibility."
136+
if ($Encoding -notmatch "UTF8") {
137+
Write-Warning "For maximum portability, we strongly recommend you build your script modules with UTF8 encoding (with a BOM, for backwards compatibility to PowerShell 5)."
138138
}
139139
}
140140
process {
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
function Set-Source {
1+
function Set-Source {
22
[CmdletBinding()]
33
[Alias("ss", "ssou")]
44
param()
5+
"sto͞o′pĭd"
56
}

0 commit comments

Comments
 (0)