Skip to content

Commit f9f70da

Browse files
nohwndCopilot
andcommitted
Fix #2649: Catch ToString() exceptions in NUnit3 output
Copilot-generated fix. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent d5f7c87 commit f9f70da

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/functions/TestResults.NUnit3.ps1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,12 @@ function Format-CDataString ($Output) {
554554
$linesCount = $out.Length
555555
$o = for ($i = 0; $i -lt $linesCount; $i++) {
556556
# The input is array of objects, convert them to strings.
557-
$line = if ($null -eq $out[$i]) { [String]::Empty } else { $out[$i].ToString() }
557+
$line = if ($null -eq $out[$i]) {
558+
[String]::Empty
559+
}
560+
else {
561+
try { $out[$i].ToString() } catch { "<Output object ToString() failed: $($_.Exception.Message)>" }
562+
}
558563

559564
if (0 -gt $line.IndexOfAny($script:invalidCDataChars)) {
560565
# No special chars that need replacing.

0 commit comments

Comments
 (0)