You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Joey Aiello (@joeyaiello) do we need to fix this as a bug? A mixed-encoding file is just... wrong. It's bad input. I'm not really sure what Get-ChildItem should even do about it.
Open question: what's the default encoding on OS X?
PS does add a BOM to outputted files (we need to investigate exactly where)
Linux UX sync agrees that "doing the right thing" means making sure that PowerShell's default behavior works best with the tooling and ecosystem where it exists. Therefore, we shouldn't break the existing behavior on Windows, and we should change the behavior on Linux. To "do the right thing" on Linux, we have to make sure we don't ever add a BOM on Linux.
We have to test the non-BOM UTF-8 file generated on Linux can be read properly on Windows.
These changes would need to be made in the following cmdlets:
Out-File
Set-Content
We should also create an environment OR PS variable like $DefaultFileEncoding or $FileEncoding that changes the default behavior of the above cmdlets.
i validated that .NET does put a BOM in the file (in a similar way that we open files), and that our cmdlets do not do anything specific to add the BOM.
$ dotnet run
$ foriin*.log;do file $i;done
ASCII.log: ASCII text
Default.log: ASCII text
Unicode.log: Little-endian UTF-16 Unicode text
UTF8-Default.log: ASCII text
UTF8-ExplicitBOM.log: UTF-8 Unicode (with BOM) text
Obviously that text was from other experiments 😄 If you include some non-ASCII text:
String[]lines={"Normal ASCII text","你好"};
You get:
ASCII.log: ASCII text
Default.log: UTF-8 Unicode text
Unicode.log: Little-endian UTF-16 Unicode text
UTF8-Default.log: UTF-8 Unicode text
UTF8-ExplicitBOM.log: UTF-8 Unicode (with BOM) text
Which makes sense, as .NET is properly giving up on encoding non-ASCII characters for ASCII, but encodes as UTF-8 as it's supposed to:
$ cat ASCII.log
Normal ASCII text
??
$ cat UTF8-Default.log
Normal ASCII text
你好
I just checked with Eric Erhardt (@eerhardt), and he confirmed this is the same behavior as .NET 4.6.1. The two different "default" UTF-8 constructors differ in BOM usage.
Activity
joeyaiello commentedon Mar 24, 2016
Need to discuss this at greater length. Some thoughts:
andyleejordan commentedon Apr 13, 2016
Joey Aiello (@joeyaiello) do we need to fix this as a bug? A mixed-encoding file is just... wrong. It's bad input. I'm not really sure what
Get-ChildItemshould even do about it.jpsnover commentedon Apr 14, 2016
CAT works so why would it be OK for Get-ChildItem to not work?
"If you want things to work avoid the PS tools?"
On Wed, Apr 13, 2016 at 11:06 AM, Andy Schwartzmeyer <
[email protected]> wrote:
joeyaiello commentedon May 16, 2016
Linux UX sync agrees that "doing the right thing" means making sure that PowerShell's default behavior works best with the tooling and ecosystem where it exists. Therefore, we shouldn't break the existing behavior on Windows, and we should change the behavior on Linux. To "do the right thing" on Linux, we have to make sure we don't ever add a BOM on Linux.
We have to test the non-BOM UTF-8 file generated on Linux can be read properly on Windows.
These changes would need to be made in the following cmdlets:
We should also create an environment OR PS variable like
$DefaultFileEncodingor$FileEncodingthat changes the default behavior of the above cmdlets.JamesWTruher commentedon May 16, 2016
i validated that .NET does put a BOM in the file (in a similar way that we open files), and that our cmdlets do not do anything specific to add the BOM.
It is the case that if you change to utf8 encoding the appropriate BOM is written in the file,
andyleejordan commentedon May 16, 2016
James Truher (@JamesWTruher) the results are different on Linux with .NET Core:
Out-File
PowerShell, on Linux, prepends a BOM when using UTF-8 encoding:
.NET Encoding
andyleejordan commentedon May 16, 2016
Obviously that text was from other experiments 😄 If you include some non-ASCII text:
You get:
Which makes sense, as .NET is properly giving up on encoding non-ASCII characters for ASCII, but encodes as UTF-8 as it's supposed to:
$ cat ASCII.log Normal ASCII text ?? $ cat UTF8-Default.log Normal ASCII text 你好andyleejordan commentedon May 16, 2016
.NET Core's
UTF8Encoderis specifically set to not emit a BOM by default. (Link obtained from the API browser.)lzybkr commentedon May 16, 2016
I think we're just using https://github.com/dotnet/coreclr/blob/master/src/mscorlib/src/System/Text/Encoding.cs/#L1542 which passes true so the behavior should be the same on Linux.
andyleejordan commentedon May 16, 2016
OMG the fact that
UTF8EncodingandEncoding.UTF8have different explicit default behaviors is absurd.andyleejordan commentedon May 16, 2016
I just checked with Eric Erhardt (@eerhardt), and he confirmed this is the same behavior as .NET 4.6.1. The two different "default" UTF-8 constructors differ in BOM usage.
33 remaining items
regs01 commentedon May 16, 2017
My humble opinion shares some other opinions above. Default for Out-File should be UTF8 without BOM in every system.
SteveL-MSFT commentedon Sep 30, 2017
For 6.0.0 release we'll be doing a reduced scope version of this #4878
joeyaiello commentedon Dec 19, 2017
James Truher (@JamesWTruher) could you clarify here what wasn't achieved by the implementation that we're shipping in 6.0?
SteveL-MSFT commentedon Jan 2, 2018
The original issue from Jeffrey Snover (@jpsnover) no longer repros with RC2 with James Truher (@JamesWTruher)'s changes. I believe the change from Jim is that we default
$OutputEncodingto utf-8 NoBOM instead of ASCII.