Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Change default encoding for backwards compatibility
Per discussion on #83
  • Loading branch information
Jaykul committed Dec 19, 2019
commit 783a886e02307fe145cb45ee3ddd312dccfe5476
4 changes: 2 additions & 2 deletions Source/Private/SetModuleContent.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function SetModuleContent {

# The encoding defaults to UTF8 (or UTF8NoBom on Core)
[Parameter(DontShow)]
[string]$Encoding = $(if($IsCoreCLR) { "UTF8NoBom" } else { "UTF8" })
[string]$Encoding = $(if($IsCoreCLR) { "UTF8Bom" } else { "UTF8" })
)
begin {
Push-Location $WorkingDirectory -StackName SetModuleContent
Expand Down Expand Up @@ -64,4 +64,4 @@ function SetModuleContent {
$SetContent.End()
Pop-Location -StackName SetModuleContent
}
}
}
8 changes: 4 additions & 4 deletions Source/Public/Build-Module.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ function Build-Module {

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

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

begin {
if ($Encoding -ne "UTF8") {
Write-Warning "We strongly recommend you build your script modules with UTF8 encoding for maximum cross-platform compatibility."
if ($Encoding -notmatch "UTF8") {
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)."
}
}
process {
Expand Down
3 changes: 2 additions & 1 deletion Tests/Integration/Source1/Public/Set-Source.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
function Set-Source {
function Set-Source {
[CmdletBinding()]
[Alias("ss", "ssou")]
param()
"sto͞o′pĭd"
}