From 361c34da8e9c7d78d81e2f8d8f4a6d755a9e45e9 Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Tue, 16 Jan 2018 17:28:23 -0800 Subject: [PATCH 1/3] encoding for new-modulemanifest on all platforms should be utf8nobom --- .../engine/Modules/NewModuleManifestCommand.cs | 4 ---- .../engine/Module/NewModuleManifest.Tests.ps1 | 14 +++----------- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/src/System.Management.Automation/engine/Modules/NewModuleManifestCommand.cs b/src/System.Management.Automation/engine/Modules/NewModuleManifestCommand.cs index 30520c0c5bf..aa7ca908c38 100644 --- a/src/System.Management.Automation/engine/Modules/NewModuleManifestCommand.cs +++ b/src/System.Management.Automation/engine/Modules/NewModuleManifestCommand.cs @@ -941,11 +941,7 @@ protected override void EndProcessing() 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, diff --git a/test/powershell/engine/Module/NewModuleManifest.Tests.ps1 b/test/powershell/engine/Module/NewModuleManifest.Tests.ps1 index 8508db33c1d..40aa102143e 100644 --- a/test/powershell/engine/Module/NewModuleManifest.Tests.ps1 +++ b/test/powershell/engine/Module/NewModuleManifest.Tests.ps1 @@ -9,14 +9,7 @@ Describe "New-ModuleManifest tests" -tags "CI" { } BeforeAll { - if ($IsWindows) - { - $ExpectedManifestBytes = @(255,254,35,0,13,0,10,0) - } - else - { - $ExpectedManifestBytes = @(35,10) - } + $ExpectedManifestBytes = @(35,10) } It "Uris with spaces are allowed and escaped correctly" { @@ -38,10 +31,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 } From 952a576e3e90f234d8d0f7db42f1bc094cb4af3a Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Tue, 16 Jan 2018 17:56:34 -0800 Subject: [PATCH 2/3] address PR feedback --- .../Modules/NewModuleManifestCommand.cs | 22 +++++++++---------- .../engine/Module/NewModuleManifest.Tests.ps1 | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/System.Management.Automation/engine/Modules/NewModuleManifestCommand.cs b/src/System.Management.Automation/engine/Modules/NewModuleManifestCommand.cs index aa7ca908c38..c83b97245d4 100644 --- a/src/System.Management.Automation/engine/Modules/NewModuleManifestCommand.cs +++ b/src/System.Management.Automation/engine/Modules/NewModuleManifestCommand.cs @@ -939,17 +939,17 @@ protected override void EndProcessing() // Now open the output file... PathUtils.MasterStreamOpen( - this, - filePath, - new UTF8Encoding(false), // UTF-8, no BOM - /* defaultEncoding */ false, - /* Append */ false, - /* Force */ false, - /* NoClobber */ false, - out fileStream, - out streamWriter, - out readOnlyFileInfo, - false + cmdlet : this, + filePath : filePath, + resolvedEncoding : new UTF8Encoding(false), // UTF-8, no BOM + defaultEncoding : false, + Append : false, + Force : false, + NoClobber : false, + fileStream : out fileStream, + streamWriter : out streamWriter, + readOnlyFileInfo : out readOnlyFileInfo, + isLiteralPath : false ); try diff --git a/test/powershell/engine/Module/NewModuleManifest.Tests.ps1 b/test/powershell/engine/Module/NewModuleManifest.Tests.ps1 index 40aa102143e..f6646addf79 100644 --- a/test/powershell/engine/Module/NewModuleManifest.Tests.ps1 +++ b/test/powershell/engine/Module/NewModuleManifest.Tests.ps1 @@ -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" } From 8f80cc92c8e79f506a65f9ea9152d79c491edc8c Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Tue, 16 Jan 2018 19:23:52 -0800 Subject: [PATCH 3/3] fix test --- .../engine/Modules/NewModuleManifestCommand.cs | 2 +- test/powershell/engine/Module/NewModuleManifest.Tests.ps1 | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/System.Management.Automation/engine/Modules/NewModuleManifestCommand.cs b/src/System.Management.Automation/engine/Modules/NewModuleManifestCommand.cs index c83b97245d4..981c9b19af4 100644 --- a/src/System.Management.Automation/engine/Modules/NewModuleManifestCommand.cs +++ b/src/System.Management.Automation/engine/Modules/NewModuleManifestCommand.cs @@ -941,7 +941,7 @@ protected override void EndProcessing() PathUtils.MasterStreamOpen( cmdlet : this, filePath : filePath, - resolvedEncoding : new UTF8Encoding(false), // UTF-8, no BOM + resolvedEncoding : new UTF8Encoding(encoderShouldEmitUTF8Identifier : false), defaultEncoding : false, Append : false, Force : false, diff --git a/test/powershell/engine/Module/NewModuleManifest.Tests.ps1 b/test/powershell/engine/Module/NewModuleManifest.Tests.ps1 index f6646addf79..ce69ee44ed0 100644 --- a/test/powershell/engine/Module/NewModuleManifest.Tests.ps1 +++ b/test/powershell/engine/Module/NewModuleManifest.Tests.ps1 @@ -9,7 +9,11 @@ Describe "New-ModuleManifest tests" -tags "CI" { } BeforeAll { - $ExpectedManifestBytes = @(35,10) + if ($IsWindows) { + $ExpectedManifestBytes = @(35,13) # CR + } else { + $ExpectedManifestBytes = @(35,10) # LF + } } It "Uris with spaces are allowed and escaped correctly" {