Skip to content

Commit

Permalink
Fix a bug in how Write-Host handles XmlNode object (PowerShell#24669
Browse files Browse the repository at this point in the history
)
  • Loading branch information
brendandburns authored Dec 13, 2024
1 parent a2ac229 commit 90b0149
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections;
using System.Management.Automation;
using System.Text;
using System.Xml;

namespace Microsoft.PowerShell.Commands
{
Expand Down Expand Up @@ -59,6 +60,10 @@ private string ProcessObject(object o)
return s;
}
}
else if (o is XmlNode xmlNode)
{
return xmlNode.Name;
}
else if (o is IEnumerable enumerable)
{
// unroll enumerables, including arrays.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ Describe "Write-Host with TestHostCS" -Tags "CI" {
@{ Name = '-Separator, colors and -NoNewLine'; Command = "Write-Host a,b,c -Separator ',' -ForegroundColor Yellow -BackgroundColor DarkBlue -NoNewline"; returnCount = 1; returnValue = @("Yellow:DarkBlue:a,b,c:NoNewLine"); returnInfo = @("a,b,c") }
@{ Name = '-NoNewline:$true and colors'; Command = "Write-Host a,b -NoNewline:`$true -ForegroundColor Red -BackgroundColor Green;Write-Host a,b"; returnCount = 2; returnValue = @("Red:Green:a b:NoNewLine", "White:Black:a b:NewLine"); returnInfo = @("a b", "a b") }
@{ Name = '-NoNewline:$false and colors'; Command = "Write-Host a,b -NoNewline:`$false -ForegroundColor Red -BackgroundColor Green;Write-Host a,b"; returnCount = 2; returnValue = @("Red:Green:a b:NewLine","White:Black:a b:NewLine"); returnInfo = @("a b", "a b") }
@{ Name = 'XMLElement'; Command = "Write-Host ([xml] '<OhElement>Where art thou?</OhElement>').DocumentElement"; returnCount = 1; returnValue = @("White:Black:OhElement:NewLine"); returnInfo = @("OhElement") }
@{ Name = 'XMLDocument'; Command = "Write-Host ([system.xml.xmldocument] '<OhElement>Where art thou?</OhElement>').DocumentElement"; returnCount = 1; returnValue = @("White:Black:OhElement:NewLine"); returnInfo = @("OhElement") }
)

}
Expand Down

0 comments on commit 90b0149

Please sign in to comment.