From 13af0b7a68cd2a5ac77415daf92ae8f1986398b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Thu, 20 Feb 2025 20:44:08 +0100 Subject: [PATCH] More escaping in nunit3 xml --- src/functions/TestResults.NUnit3.ps1 | 7 ++++--- test.ps1 | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/functions/TestResults.NUnit3.ps1 b/src/functions/TestResults.NUnit3.ps1 index 69675059b..0831a8466 100644 --- a/src/functions/TestResults.NUnit3.ps1 +++ b/src/functions/TestResults.NUnit3.ps1 @@ -516,8 +516,9 @@ function Write-NUnit3TestCaseAttributes { $XmlWriter.WriteAttributeString('id', (Get-NUnit3NodeId)) # Workaround - name-attribute should be $name, but CI-reports don't show the tree-view nor use fullname # See https://github.com/pester/Pester/issues/1530#issuecomment-1186187298 - $XmlWriter.WriteAttributeString('name', $fullname) - $XmlWriter.WriteAttributeString('fullname', $fullname) + $escapedFullName = (Format-CDataString $fullname) + $XmlWriter.WriteAttributeString('name', $escapedFullName) + $XmlWriter.WriteAttributeString('fullname', $escapedFullName) $XmlWriter.WriteAttributeString('methodname', $TestResult.Name) $XmlWriter.WriteAttributeString('classname', $TestResult.Block.Path -join '.') $XmlWriter.WriteAttributeString('runstate', $runstate) @@ -646,7 +647,7 @@ function Write-NUnit3DataProperty ([System.Collections.IDictionary] $Data, [Syst $XmlWriter.WriteStartElement('property') $XmlWriter.WriteAttributeString('name', $name) - $XmlWriter.WriteAttributeString('value', $formattedValue) + $XmlWriter.WriteAttributeString('value', (Format-CDataString $formattedValue)) $XmlWriter.WriteEndElement() # Close property } } diff --git a/test.ps1 b/test.ps1 index 553cd698a..dfbb5c89b 100644 --- a/test.ps1 +++ b/test.ps1 @@ -185,6 +185,7 @@ if ($CI) { $configuration.CodeCoverage.Enabled = $false $configuration.TestResult.Enabled = $true + $configuration.TestResult.OutputFormat = 'NUnit3' } $r = Invoke-Pester -Configuration $configuration