Skip to content

Fix a bug in how Write-Host handles XML Elements - #24669

Merged
Dongbo Wang (daxian-dbw) merged 4 commits into
PowerShell:masterfrom
brendandburns:master
Dec 13, 2024
Merged

Dongbo Wang (daxian-dbw) merged 4 commits into
PowerShell:masterfrom
brendandburns:master

Conversation

@brendandburns

Copy link
Copy Markdown
Contributor

PR Summary

Changes how the Write-Host cmdlet handles XMLElements, fixes #24508

PR Context

I'm not positive this is the right fix, spiritually I could get behind using .OuterXml instead which would print the whole XML document from that element, which seems aligned with the iteration of an Enumerable.

Either way, it is definitely the case that the current code doesn't work as expected.

PR Checklist

@brendandburns

Brendan Burns (brendandburns) commented Dec 12, 2024 •

Copy link
Copy Markdown
Contributor Author

Let me know if you want me to update unit tests for this case.

Added a unit test.

@brendandburns

Copy link
Copy Markdown
Contributor Author

Another option would be to return enumerable.ToString() if the enumerable has zero elements in it (the case with XMLText) but that prints System.Xml.XmlText which I don't really think is the right output for Write-Host ([xml] '<OhElement>Where art thou?</OhElement>').DocumentElement

…teConsoleCmdlet.cs

Co-authored-by: Dongbo Wang <dongbow@microsoft.com>
…t.Tests.ps1

Co-authored-by: Steve Lee <slee@microsoft.com>
@daxian-dbw
Dongbo Wang (daxian-dbw) merged commit 90b0149 into PowerShell:master Dec 13, 2024
@jshigetomi Justin Chung (jshigetomi) added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Jan 14, 2025
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Write-Host renders an [xml] or [XmlElement] instance as an empty line.

5 participants