Note: Unlike #13677, Windows PowerShell exhibits the same problem.
Start-Transcript -Append tries to match the target file's existing character encoding.
As an aside: The built-in cmdlets are inconsistent with respect to this behavior: Out-File -Append does not match the existing encoding, whereas Export-Csv -Append, Start-Transcript -Append, and Add-Content do.
In the absence of a BOM in the target file, ASCII encoding is currently assumed, which results in the loss of non-ASCII-range characters, as they are transliterated to verbatim ?.
UTF-8 (by definition BOM-less, since a file is being appended to) should be assumed and used instead.
Steps to reproduce
# To surface the bug, make sure that the target file exists and doesn't have a BOM.
'ä' > temp:/$PID.txt
# Start the transcript and *append* to the existing file:
$null = Start-Transcript -Append temp:/$PID.txt
'ü' # output a string with a non-ASCII-range character
$null = Stop-Transcript
Select-String -Quiet 'ü' temp:/$PID.txt | Should -BeTrue
Remove-Item temp:/$PID.txt
Expected behavior
The test should succeed.
Actual behavior
The test fails, because ü was transliterated to verbatim ?.
Environment data
PowerShell Core 7.1.0-preview.7
Note: Unlike #13677, Windows PowerShell exhibits the same problem.
Start-Transcript -Appendtries to match the target file's existing character encoding.As an aside: The built-in cmdlets are inconsistent with respect to this behavior:
Out-File -Appenddoes not match the existing encoding, whereasExport-Csv -Append,Start-Transcript -Append, andAdd-Contentdo.In the absence of a BOM in the target file, ASCII encoding is currently assumed, which results in the loss of non-ASCII-range characters, as they are transliterated to verbatim
?.UTF-8 (by definition BOM-less, since a file is being appended to) should be assumed and used instead.
Steps to reproduce
Expected behavior
The test should succeed.
Actual behavior
The test fails, because
üwas transliterated to verbatim?.Environment data