-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Description
For reference:
- Issue: Save pure string text to file with redirection or
Out-Fileunexpectedly strip off VT sequences from the original text #17452 - PR that fixed the issue: Make
Out-StringandOut-Filekeep string input unchanged #17455
Context summary
The previous behavior in 7.2.x is: Out-File and Out-String remove escape sequences from the passed-in strings when $PSStyle.OutputRendering is Host or PlainText.
There are some problems with this behavior, especially when having Host to be the default value for $PSStyle.OutputRendering. See #17455 (comment) for the details of those problems.
Therefore, that behavior was changed by #17455 to be:
- when the input object is pure string, these 2 cmdlets keep the string input unchanged regardless of the
RenderingOutputsetting - when the input object needs to have formatting views applied to it, these 2 cmdlets remove escape sequences from the formatting output strings based on the
RenderingOutputsetting, which is the same as the existing behavior.
Recommendation from PowerShell Committee
The committee reviewed #17455 and recommended to add a new parameter to Out-String and Out-File to keep the previous behavior. Quote the comments #17455 (review) and #17455 (comment) below:
I think we should seriously consider adding a parameter to out-string and out-file which retains our current behavior. Perhaps a parameter
-AsPlainTextor some such will allow users to have the older behavior while we provide a safer default behavior.powershell-committee reviewed this, we would recommend adding a parameter to enable users to get back the previous behavior.