Change $OutputEncoding to be utf8 without BOM rather than ASCII (#5369)

This commit is contained in:
James Truher [MSFT] 2017-11-07 14:49:14 -08:00 committed by Dongbo Wang
parent 610c70d952
commit fe3e44f305
3 changed files with 9 additions and 2 deletions

View File

@ -4410,7 +4410,7 @@ end
// Variable which controls the encoding for piping data to a NativeCommand
new SessionStateVariableEntry(
SpecialVariables.OutputEncoding,
System.Text.Encoding.ASCII,
Utils.utf8NoBom,
RunspaceInit.OutputEncodingDescription,
ScopedItemOptions.None,
new ArgumentTypeConverterAttribute(typeof(System.Text.Encoding))

View File

@ -1798,7 +1798,7 @@ namespace System.Management.Automation
//from the current scope so a script or function can use a different encoding
//than global value.
Encoding pipeEncoding = _command.Context.GetVariableValue(SpecialVariables.OutputEncodingVarPath) as System.Text.Encoding ??
Encoding.ASCII;
Utils.utf8NoBom;
_streamWriter = new StreamWriter(process.StandardInput.BaseStream, pipeEncoding);
_streamWriter.AutoFlush = true;

View File

@ -1,3 +1,10 @@
Describe 'Native pipeline should have proper encoding' -tags 'CI' {
It '$OutputEncoding should be set to UTF8 without BOM' {
$OutputEncoding.BodyName | Should Be "utf-8"
$OutputEncoding.GetPreamble().Length | Should Be 0
}
}
Describe 'native commands with pipeline' -tags 'Feature' {
BeforeAll {