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
It seems we can safely migrate to a common pattern "Unicode", "UTF7", "UTF8", "ASCII", "UTF32", "BigEndianUnicode", "Default", "OEM".
Format-Hex was converted from function to cmdlet. I believe we can enhance it.
Out-File. My understanding is that "Unknown" and "String" encodings is output encodings and don't be used as input encodings. So we can and should remove them from Out-File cmdlet.
I think I agree in principle regarding removing Unknown and String from Out-File, but don't have enough data to approve the change.
I believe Out-File uses the encoding when you specify -Append, but you'd need to confirm.
A search of GitHub for Out-File could help provide some data, but finding uses is the only reliable way of making a a decision - to keep - because lack of usage on GitHub doesn't mean the encoding values aren't in use, just that those uses aren't on GitHub or other public sources of scripts.
I did not found using of EncodingConversion.Unknown and EncodingConversion.String in the repo. It seems it's just a mirror of FileProvider types.
Search of GitHub. Common usage is: Out-File -Encoding Ascii Out-File -Encoding Uft8
I did not found (manual search only) "Unknown" and "String" with "out-file -encoding" at all.
Ilya (@iSazonov): I also can't comment on current usage, except to say I've never personally used the Unknown and String encodings.
I agree that Unknown doesn't make sense in output cmdlets. In practice, Out-File / Out-File -Append and Set-Content / Add-Content all treat Unknown as Unicode (UTF-16 LE) - cc Jason Shirk (@lzybkr)
That is, when appending to an existing file, the behavior does not depend on that file's existing encoding.
As far as I know, the only cmdlet that changes its default encoding based on preexisting file content is Export-Csv -Append (and does so in a half-broken manner: preexisting "ANSI" content (Default) results in UTF-8 content getting appended).
I'm still not sure what the purpose of String is. Its behavior differs between Out-File and Set-Content - unlike with Unknown, String seems to result in the cmdlets' respective defaults (Unicode for Out-File, Default ("ANSI" on Windows) for Set-Content).
In context of the Issue we should ignore difference between Utility cmdlets and FileProvider cmdlets. As result we should conclude that we could safely remove String and Unknown from Out-File.
But I see another question: why Out-File cmdlet uses the Utility cmdlet code base but not FileProvider code base for encoding? It seems it must be placed together with Get-Content and Set-Content. Nevertheless, even if we agree to do this cmdlet as FileProvider cmdlet then we see that we could safely remove String and Unknown from Out-File.
Also I reviewed MSDN documentation: there is no exact description of use String and Unknown. If these features were never documented properly then no one can use them correctly. It looks as if the project was not fully realized or abandoned long ago.
P.S.: For symmetry and to support all Unicode-mandated encoding forms, we should support UTF-32 BE (big-endian) as well (the UTF32 value is UTF-32 LE).
Activity
iSazonov commentedon May 3, 2017
Jason Shirk (@lzybkr) Could you please comment and approve this change?
lzybkr commentedon May 3, 2017
I think I agree in principle regarding removing
UnknownandStringfromOut-File, but don't have enough data to approve the change.I believe
Out-Fileuses the encoding when you specify-Append, but you'd need to confirm.A search of GitHub for
Out-Filecould help provide some data, but finding uses is the only reliable way of making a a decision - to keep - because lack of usage on GitHub doesn't mean the encoding values aren't in use, just that those uses aren't on GitHub or other public sources of scripts.iSazonov commentedon May 4, 2017
Jason Shirk (@lzybkr) Thanks for comments.
I did not found using of
EncodingConversion.UnknownandEncodingConversion.Stringin the repo. It seems it's just a mirror of FileProvider types.Search of GitHub. Common usage is:
Out-File -Encoding AsciiOut-File -Encoding Uft8I did not found (manual search only) "Unknown" and "String" with "out-file -encoding" at all.
iSazonov commentedon May 4, 2017
Michael Klement (@mklement0) Have you any special thoughts about the Issue?
mklement0 commentedon May 5, 2017
Ilya (@iSazonov): I also can't comment on current usage, except to say I've never personally used the
UnknownandStringencodings.I agree that
Unknowndoesn't make sense in output cmdlets. In practice,Out-File/Out-File -AppendandSet-Content/Add-Contentall treatUnknownasUnicode(UTF-16 LE) - cc Jason Shirk (@lzybkr)As far as I know, the only cmdlet that changes its default encoding based on preexisting file content is
Export-Csv -Append(and does so in a half-broken manner: preexisting "ANSI" content (Default) results in UTF-8 content getting appended).I'm still not sure what the purpose of
Stringis. Its behavior differs betweenOut-FileandSet-Content- unlike withUnknown,Stringseems to result in the cmdlets' respective defaults (UnicodeforOut-File,Default("ANSI" on Windows) forSet-Content).The following code demonstrates this:
As for the input side of things, using the example of
Get-Content:In practice,
Unknownis interpreted the same way as withOut-FileandSet-Content,Unknownis effectively the same asUnicode(UTF-16 LE).Similarly,
Stringseems to be equivalent to the default behavior (as if-Encodinghad not been specified): which means:DefaultPurely from a naming standpoint, it is this variable behavior that deserves to be called
Unknown.iSazonov commentedon May 5, 2017
Michael Klement (@mklement0) Thanks for great comments!
In context of the Issue we should ignore difference between Utility cmdlets and FileProvider cmdlets. As result we should conclude that we could safely remove
StringandUnknownfromOut-File.But I see another question: why Out-File cmdlet uses the Utility cmdlet code base but not FileProvider code base for encoding? It seems it must be placed together with
Get-ContentandSet-Content. Nevertheless, even if we agree to do this cmdlet as FileProvider cmdlet then we see that we could safely removeStringandUnknownfromOut-File.Also I reviewed MSDN documentation: there is no exact description of use
StringandUnknown. If these features were never documented properly then no one can use them correctly. It looks as if the project was not fully realized or abandoned long ago.mklement0 commentedon May 5, 2017
Ilya (@iSazonov)
I fully agree re removal of
StringandUnknown; let's see what the powers that be decide.Good point re code base - had never paid attention to that.
mklement0 commentedon May 5, 2017
P.S.: For symmetry and to support all Unicode-mandated encoding forms, we should support UTF-32 BE (big-endian) as well (the
UTF32value isUTF-32 LE).I'll address this and other encoding-related issues in an upcoming post in PowerShell/PowerShell-RFC#71
iSazonov commentedon Aug 16, 2018
It was fixed with implementing RFC0020 in #5080