Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

StringDecorated class doesn't recognize <esc>[m as the ANSI reset escape sequence, requires <esc>[0m #19246

Copy link
Copy link
@mklement0

Description

@mklement0
Issue body actions

Prerequisites

Steps to reproduce

"`e[m " is a valid ANSI escape sequence that resets current formatting, short for "`e[0m "

The StringDecorated currently doesn't recognize it, and retains it as part of the data when plain-text conversion is requested.

# If you output the string directly to the terminal, you'll see that the trailing "." is NOT green anymore,
# proving that "`e[m"` was effective in resetting the color.
([System.Management.Automation.Internal.StringDecorated]::new("`e[32mgreen`e[m.")).ToString('PlainText') | Format-Hex

Note:

  • Because terminals recognize "`e[m " correctly, the problem is usually hidden when the class is used behind the scenes in conjunction with $PSStyle.OutputRendering = 'PlainText', e.g. with
    $PSStyle.OutputRendering = 'PlainText'; wsl -e printf '\e[32mgreen\e[m.' | Out-Host.

  • However, due to the - inappropriately closed - Streamed executable output prints Ansi Escaping in Write-* Commandlets #18771 - it currently does surface in conhost.exe windows on Windows.

Expected behavior

Label: String (System.String) <7E780A95>

          Offset Bytes                                           Ascii
                 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
          ------ ----------------------------------------------- -----
0000000000000000 67 72 65 65 6E 2E                               green.

Actual behavior

Label: String (System.String) <56784E4B>

          Offset Bytes                                           Ascii
                 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
          ------ ----------------------------------------------- -----
0000000000000000 67 72 65 65 6E 1B 5B 6D 2E                      green�[m.

Note the extraneous �[m part in the Ascii column, showing that `e[m was unexpectedly retained.

Error details

No response

Environment data

PowerShell Core 7.4.0-preview.1

Visuals

No response

Reactions are currently unavailable

Metadata

Metadata

Assignees

Labels

Resolution-FixedThe issue is fixed.The issue is fixed.WG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtime

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.