Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 13, 2024

Conversation

brendandburns
Copy link
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
Copy link
Contributor Author

brendandburns commented Dec 12, 2024

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

Added a unit test.

@brendandburns
Copy link
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

@daxian-dbw daxian-dbw merged commit 90b0149 into PowerShell:master Dec 13, 2024
37 checks passed
@jshigetomi 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
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