Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -940,8 +940,12 @@ protected override void EndProcessing()
// Now open the output file...
PathUtils.MasterStreamOpen(
this,
filePath,
EncodingConversion.Unicode,
filePath,
#if UNIX
new UTF8Encoding(false), // UTF-8, no BOM
#else
EncodingConversion.Unicode, // UTF-16 with BOM
#endif
/* defaultEncoding */ false,
/* Append */ false,
/* Force */ false,
Expand Down Expand Up @@ -1167,5 +1171,5 @@ private void ValidateUriParameterValue(Uri uri, string parameterName)
}
}

#endregion
#endregion
} // Microsoft.PowerShell.Commands
25 changes: 25 additions & 0 deletions test/powershell/engine/Module/NewModuleManifest.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ Describe "New-ModuleManifest tests" -tags "CI" {
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue testdrive:/module
}

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

It "Uris with spaces are allowed and escaped correctly" {
$testUri = [Uri]"http://foo.com/hello world"
$absoluteUri = $testUri.AbsoluteUri
Expand All @@ -20,6 +31,20 @@ Describe "New-ModuleManifest tests" -tags "CI" {
$module.PrivateData.PSData.ProjectUri | Should BeExactly $absoluteUri
}

function TestNewModuleManifestEncoding {
param ([byte[]]$expected)
New-ModuleManifest -Path $testModulePath
(Get-Content -Encoding Byte -Path $testModulePath -TotalCount $expected.Length) -join ',' | Should Be ($expected -join ',')
}

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)
TestNewModuleManifestEncoding -expected $ExpectedManifestBytes
}

It "Relative URIs are not allowed" {
$testUri = [Uri]"../foo"

Expand Down