René's URL Explorer Experiment


Title: Save pure string text to file with redirection or `Out-File` unexpectedly strip off VT sequences from the original text · Issue #17452 · PowerShell/PowerShell · GitHub

Open Graph Title: Save pure string text to file with redirection or `Out-File` unexpectedly strip off VT sequences from the original text · Issue #17452 · PowerShell/PowerShell

X Title: Save pure string text to file with redirection or `Out-File` unexpectedly strip off VT sequences from the original text · Issue #17452 · PowerShell/PowerShell

Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerShell 5.1 and PowerShell. Steps to reprodu...

Open Graph Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerSh...

X Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerSh...

Opengraph URL: https://github.com/PowerShell/PowerShell/issues/17452

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Save pure string text to file with redirection or `Out-File` unexpectedly strip off VT sequences from the original text","articleBody":"### Prerequisites\r\n\r\n- [X] Write a descriptive title.\r\n- [X] Make sure you are able to repro it on the [latest released version](https://github.com/PowerShell/PowerShell/releases)\r\n- [X] Search the existing issues.\r\n- [X] Refer to the [FAQ](https://github.com/PowerShell/PowerShell/blob/master/docs/FAQ.md).\r\n- [X] Refer to [Differences between Windows PowerShell 5.1 and PowerShell](https://docs.microsoft.com/powershell/scripting/whats-new/differences-from-windows-powershell).\r\n\r\n### Steps to reproduce\r\n\r\nThis happens in 7.3.0-preview.4, and all other 7.3 preview versions.\r\n**This is a regression from both 7.0.x and 7.2.x (both are LTS versions).**\r\n\r\nContent of the test file `try.ps1`: (Ansi escape sequence is used for color).\r\n```\r\nRead-Host -Prompt \"\u001b[33mEnter your device code\u001b[0m\"\r\n```\r\n\r\nTry replacing ``\"`r`n\"`` with ``\"`n\"`` for the content in the file and save it to another file:\r\n```pwsh\r\n(Get-Content .\\try.ps1 -Raw).Replace(\"`r`n\", \"`n\") > new.ps1\r\n## Or, (Get-Content .\\try.ps1 -Raw).Replace(\"`r`n\", \"`n\")  | Out-File new.ps1\r\n```\r\n\r\nNow all Ansi escape sequences are lost in the content of `new.ps1`:\r\n```\r\nRead-Host -Prompt \"Enter your device code\"\r\n```\r\n---------------------------------------------------------------\r\n\r\n`Set-Content` works as expected, which preserves the Ansi escape sequences.\r\n\r\n```pwsh\r\n(Get-Content .\\try.ps1 -Raw).Replace(\"`r`n\", \"`n\") | Set-Content new.ps1\r\n```\r\n---------------------------------------------------------------\r\n\r\nBehavior in 7.0.11:\r\n\r\n![image](https://user-images.githubusercontent.com/127450/170773178-9b3a660c-af15-4383-a0a2-9adc83dbdb3b.png)\r\n\r\nBehavior in 7.2.2:\r\n\r\n![image](https://user-images.githubusercontent.com/127450/170773256-eaa5cce9-1cee-4d6e-b135-3eb120150d0a.png)\r\n\r\n-------------------------------------------\r\n\r\n### Root cause and behavior proposal\r\n\r\nThe root cause of this regression is having `Host` to be the default value for `$PSStyle.OutputRendering`, which make the `Out-*` cmdlet to strip off escape sequences from the passed-in input.\r\n\r\n- In 7.0.x, the `$PSStyle` feature is not there, so `Out-*` commands don't do anything special to Ansi escape sequences in the input.\r\n- In 7.2.x, the default value for `$PSStyle.OutputRendering` is `Ansi`, so the behavior is unchanged without a user knowing about the `$PSStyle` feature.\r\n- In 7.3, the default value is changed to `Host`, which makes `Out-*` cmdlets to always strip off escape sequences from the input, and hence the regression.\r\n\r\nI understand the purpose of having `Host` option for `$PSStyle.OutputRendering` -- it's nice to have ANSI decorations in the formatting output when it's rendered on terminal, but when redirecting the formatting out like in `Get-Process > file`, the escape sequences in the formatting output becomes annoying. The `Host` option is to tell PowerShell to not keep ANSI decorations in case of redirection (essentially `Out-File`, and basically any `Out-*` cmdlets such as `Out-String`).\r\n\r\nBut for pure string input that doesn't really go through formatting, it doesn't seem right to remove the Ansi escape sequences, given that the formatting system doesn't add any to it. The `Out-*` should treat the pure string input as is, and only remove escape sequences when the input object actually goes through formatting.\r\n\r\nSo, the **proposal** is: option `Host` makes `Out-*` cmdlets remove escape sequences only if the input object actually goes through formatting within the `Out-*` cmdlets. For string input, `Out-*` cmdlet should not do anything special regarding Ansi escape sequences.\r\n\r\n### Expected behavior\r\n\r\n```console\r\nThe content in new.ps1 should be the same as in try.ps1, except that all \"\\r\\n\" characters are replaced with \"\\n\".\r\n```\r\n\r\n\r\n### Actual behavior\r\n\r\n```console\r\nThe escape sequences in the original file was removed during redirection.\r\n```\r\n\r\n\r\n### Error details\r\n\r\n```console\r\nN/A\r\n```\r\n\r\n\r\n### Environment data\r\n\r\n```powershell\r\nPS:24> $PSVersionTable\r\n\r\nName                           Value\r\n----                           -----\r\nPSVersion                      7.3.0-preview.4\r\nPSEdition                      Core\r\nGitCommitId                    7.3.0-preview.4\r\nOS                             Microsoft Windows 10.0.19044\r\nPlatform                       Win32NT\r\nPSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}\r\nPSRemotingProtocolVersion      2.3\r\nSerializationVersion           1.1.0.1\r\nWSManStackVersion              3.0\r\n```\r\n\r\n\r\n### Visuals\r\n\r\n_No response_","author":{"url":"https://github.com/daxian-dbw","@type":"Person","name":"daxian-dbw"},"datePublished":"2022-05-27T20:13:35Z","url":"https://github.com/PowerShell/PowerShell/issues/17452"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:65e2b6fa-237a-7181-2009-108b8d17cbe9
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idCE3E:3080FC:86416:B8C83:6AFDA9FE
html-safe-nonceba3cf3e6013204044fa84b22ea6b3c4203b42d862da8b46f107fdb70e7688019
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRTNFOjMwODBGQzo4NjQxNjpCOEM4Mzo2QUZEQTlGRSIsInZpc2l0b3JfaWQiOiI0MzA4NzQyMTgxMzMxMjQ5NjYyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmacc8f5774a80ce1451bb3f4ec3ec79081da00777bdc8b9bcba86c3a99102ab5c06
hovercard-subject-tagissue:1251228366
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/17452/issue_layout
twitter:imagehttps://opengraph.githubassets.com/d6ecdfb0c2dd30b86d342282c0866dafa65c0cac69d01a0de8bad79482d4c03b/PowerShell/PowerShell/issues/17452
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/d6ecdfb0c2dd30b86d342282c0866dafa65c0cac69d01a0de8bad79482d4c03b/PowerShell/PowerShell/issues/17452
og:image:altPrerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerSh...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamedaxian-dbw
hostnamegithub.com
expected-hostnamegithub.com
Nonebc86424ef34a73b386237872800e922d149d65ba907f63d6f150a2dcb8433bea
turbo-cache-controlno-preview
go-importgithub.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git
octolytics-dimension-user_id11524380
octolytics-dimension-user_loginPowerShell
octolytics-dimension-repository_id49609581
octolytics-dimension-repository_nwoPowerShell/PowerShell
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id49609581
octolytics-dimension-repository_network_root_nwoPowerShell/PowerShell
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release0ddf53eb35c87f1f8df13dbf75c3bdadbfc6e969
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/PowerShell/PowerShell/issues/17452#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FPowerShell%2FPowerShell%2Fissues%2F17452
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FPowerShell%2FPowerShell%2Fissues%2F17452
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=PowerShell%2FPowerShell
Reloadhttps://github.com/PowerShell/PowerShell/issues/17452
Reloadhttps://github.com/PowerShell/PowerShell/issues/17452
Reloadhttps://github.com/PowerShell/PowerShell/issues/17452
PowerShellhttps://github.com/PowerShell
PowerShellhttps://github.com/PowerShell/PowerShell
Codehttps://github.com/PowerShell/PowerShell
Issues1.3k (1.3k)https://github.com/PowerShell/PowerShell/issues
Pull requests366 (366)https://github.com/PowerShell/PowerShell/pulls
Discussionshttps://github.com/PowerShell/PowerShell/discussions
Actionshttps://github.com/PowerShell/PowerShell/actions
Projectshttps://github.com/PowerShell/PowerShell/projects
Security and quality3 (3)https://github.com/PowerShell/PowerShell/security
Insightshttps://github.com/PowerShell/PowerShell/insights
https://github.com/PowerShell/PowerShell
New issuehttps://github.com/login?return_to=https://github.com/PowerShell/PowerShell/issues/17452
New issuehttps://github.com/login?return_to=https://github.com/PowerShell/PowerShell/issues/17452
#17455https://github.com/PowerShell/PowerShell/pull/17455
Save pure string text to file with redirection or Out-File unexpectedly strip off VT sequences from the original texthttps://github.com/PowerShell/PowerShell/issues/17452#top
#17455https://github.com/PowerShell/PowerShell/pull/17455
Issue-BugIssue has been identified as a bug in the producthttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22Issue-Bug%22
Resolution-FixedThe issue is fixed.https://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22Resolution-Fixed%22
WG-Enginecore PowerShell engine, interpreter, and runtimehttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22WG-Engine%22
https://github.com/daxian-dbw
Dongbo Wang (daxian-dbw)https://github.com/daxian-dbw
on May 27, 2022https://github.com/PowerShell/PowerShell/issues/17452#issue-1251228366
latest released versionhttps://github.com/PowerShell/PowerShell/releases
FAQhttps://github.com/PowerShell/PowerShell/blob/master/docs/FAQ.md
Differences between Windows PowerShell 5.1 and PowerShellhttps://docs.microsoft.com/powershell/scripting/whats-new/differences-from-windows-powershell
https://user-images.githubusercontent.com/127450/170773178-9b3a660c-af15-4383-a0a2-9adc83dbdb3b.png
https://user-images.githubusercontent.com/127450/170773256-eaa5cce9-1cee-4d6e-b135-3eb120150d0a.png
Dongbo Wang (daxian-dbw)https://github.com/daxian-dbw
Needs-TriageThe issue is new and needs to be triaged by a work group.https://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22Needs-Triage%22
WG-Enginecore PowerShell engine, interpreter, and runtimehttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22WG-Engine%22
on May 27, 2022https://github.com/PowerShell/PowerShell/issues/17452#event-6695201326
https://github.com/jhoneill
James O'Neill (jhoneill)https://github.com/jhoneill
on May 28, 2022https://github.com/PowerShell/PowerShell/issues/17452#issuecomment-1140116052
In-PRIndicates that a PR is out for the issuehttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22In-PR%22
on May 28, 2022https://github.com/PowerShell/PowerShell/issues/17452#event-6697418252
https://github.com/daxian-dbw
Dongbo Wang (daxian-dbw)https://github.com/daxian-dbw
on May 30, 2022https://github.com/PowerShell/PowerShell/issues/17452#issuecomment-1141521659
#17455https://github.com/PowerShell/PowerShell/pull/17455
#17463https://github.com/PowerShell/PowerShell/pull/17463
https://github.com/jhoneill
James O'Neill (jhoneill)https://github.com/jhoneill
on May 31, 2022https://github.com/PowerShell/PowerShell/issues/17452#issuecomment-1141779175
#17463https://github.com/PowerShell/PowerShell/pull/17463
#17455https://github.com/PowerShell/PowerShell/pull/17455
Dongbo Wang (daxian-dbw)https://github.com/daxian-dbw
Breaking-Changebreaking change that may affect usershttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22Breaking-Change%22
Issue-BugIssue has been identified as a bug in the producthttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22Issue-Bug%22
Needs-TriageThe issue is new and needs to be triaged by a work group.https://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22Needs-Triage%22
Breaking-Changebreaking change that may affect usershttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22Breaking-Change%22
on Jun 2, 2022https://github.com/PowerShell/PowerShell/issues/17452#event-6729757506
Dongbo Wang (daxian-dbw)https://github.com/daxian-dbw
completedhttps://github.com/PowerShell/PowerShell/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#17455https://github.com/PowerShell/PowerShell/pull/17455
on Jun 9, 2022https://github.com/PowerShell/PowerShell/issues/17452#event-6774031011
In-PRIndicates that a PR is out for the issuehttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22In-PR%22
on Jun 9, 2022https://github.com/PowerShell/PowerShell/issues/17452#event-6774031263
Resolution-FixedThe issue is fixed.https://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22Resolution-Fixed%22
on Jun 9, 2022https://github.com/PowerShell/PowerShell/issues/17452#event-6774031322
Sign up for freehttps://github.com/signup?return_to=https://github.com/PowerShell/PowerShell/issues/17452
Sign in to commenthttps://github.com/login?return_to=https://github.com/PowerShell/PowerShell/issues/17452
Issue-BugIssue has been identified as a bug in the producthttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22Issue-Bug%22
Resolution-FixedThe issue is fixed.https://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22Resolution-Fixed%22
WG-Enginecore PowerShell engine, interpreter, and runtimehttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22WG-Engine%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.