Skip to content

Commit

Permalink
Encoding for New-ModuleManifest on all platforms should be UTF-8 NoBOM (
Browse files Browse the repository at this point in the history
#5923)

* encoding for new-modulemanifest on all platforms should be utf8nobom
* fix test
  • Loading branch information
SteveL-MSFT authored and adityapatwardhan committed Jan 18, 2018
1 parent d3a775d commit 7437f3d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -939,21 +939,17 @@ protected override void EndProcessing()

// Now open the output file...
PathUtils.MasterStreamOpen(
this,
filePath,
#if UNIX
new UTF8Encoding(false), // UTF-8, no BOM
#else
EncodingConversion.Unicode, // UTF-16 with BOM
#endif
/* defaultEncoding */ false,
/* Append */ false,
/* Force */ false,
/* NoClobber */ false,
out fileStream,
out streamWriter,
out readOnlyFileInfo,
false
cmdlet : this,
filePath : filePath,
resolvedEncoding : new UTF8Encoding(encoderShouldEmitUTF8Identifier : false),
defaultEncoding : false,
Append : false,
Force : false,
NoClobber : false,
fileStream : out fileStream,
streamWriter : out streamWriter,
readOnlyFileInfo : out readOnlyFileInfo,
isLiteralPath : false
);

try
Expand Down
18 changes: 7 additions & 11 deletions test/powershell/engine/Module/NewModuleManifest.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Describe "New-ModuleManifest tests" -tags "CI" {
BeforeEach {
New-Item -ItemType Directory -Path testdrive:/module
$null = New-Item -ItemType Directory -Path testdrive:/module
$testModulePath = "testdrive:/module/test.psd1"
}

Expand All @@ -9,13 +9,10 @@ Describe "New-ModuleManifest tests" -tags "CI" {
}

BeforeAll {
if ($IsWindows)
{
$ExpectedManifestBytes = @(255,254,35,0,13,0,10,0)
}
else
{
$ExpectedManifestBytes = @(35,10)
if ($IsWindows) {
$ExpectedManifestBytes = @(35,13) # CR
} else {
$ExpectedManifestBytes = @(35,10) # LF
}
}

Expand All @@ -38,10 +35,9 @@ Describe "New-ModuleManifest tests" -tags "CI" {
}

It "Verify module manifest encoding" {

# verify first line of the manifest:
# on Windows platforms - 3 characters - '#' '\r' '\n' - in UTF-16 with BOM - this should be @(255,254,35,0,13,0,10,0)
# on non-Windows platforms - 2 characters - '#' '\n' - in UTF-8 no BOM - this should be @(35,10)
# 2 characters - '#' '\n' - in UTF-8 no BOM - this should be @(35,10)
TestNewModuleManifestEncoding -expected $ExpectedManifestBytes
}

Expand Down

0 comments on commit 7437f3d

Please sign in to comment.