Skip to content

Start-Transcript -Append uses lossy ASCII character encoding when appending to a BOM-less target file #13678

@mklement0

Description

@mklement0

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions