From 0072bff173a46ce1103f41a2cb71cb40715768c9 Mon Sep 17 00:00:00 2001 From: Oscar Calvo Date: Tue, 25 Jun 2024 13:51:46 -0700 Subject: [PATCH] Use unicode printable block to represent invalid characters in CData --- src/functions/TestResults.NUnit3.ps1 | 6 +++++- tst/Pester.RSpec.TestResults.NUnit3.ts.ps1 | 6 +++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/functions/TestResults.NUnit3.ps1 b/src/functions/TestResults.NUnit3.ps1 index 490a043e9..d586fff2f 100644 --- a/src/functions/TestResults.NUnit3.ps1 +++ b/src/functions/TestResults.NUnit3.ps1 @@ -537,8 +537,12 @@ function Write-NUnit3TestCaseAttributes { } function Write-NUnit3OutputElement ($Output, [System.Xml.XmlWriter] $XmlWriter) { + # The characters in the range 0x01 to 0x19 are invalid for CData + # (with the exception of the characters 0x09, 0x0A and 0x0D) + # We convert each of these using the unicode printable version, + # which is obtained by adding 0x2400 [int]$unicodeControlPictures = 0x2400 - [int[]]$validChars = (0x9,0xA,0xD) + [int[]]$validChars = (0x09,0x0A,0x0D) $outputString = @(foreach ($o in $Output) { if ($null -eq $o) { [string]::Empty diff --git a/tst/Pester.RSpec.TestResults.NUnit3.ts.ps1 b/tst/Pester.RSpec.TestResults.NUnit3.ts.ps1 index ab42036c0..15cd2a2f4 100644 --- a/tst/Pester.RSpec.TestResults.NUnit3.ts.ps1 +++ b/tst/Pester.RSpec.TestResults.NUnit3.ts.ps1 @@ -356,7 +356,7 @@ i -PassThru:$PassThru { $esc = [char][int]0x1B $bell = [char][int]0x07 $testCases = ( - "$esc[32mHello World$esc[0m", + "$esc[32mHello`tWorld$esc[0m", "Ring the bell$bell") $testCases |% { Write-Output $_ @@ -374,8 +374,8 @@ i -PassThru:$PassThru { $xmlDescribe = $xmlResult.'test-run'.'test-suite'.'test-suite' $xmlTest = $xmlDescribe.'test-case' $message = $xmlTest.output.'#cdata-section' -split "`n" - $message[0] | Verify-Equal '␛[32mHello World␛[0m' - $message[1] | Verify-Equal 'Ring the bell␇' + $message[0] | Verify-Equal "␛[32mHello`tWorld␛[0m" + $message[1] | Verify-Equal "Ring the bell␇" } t 'should use TestResult.TestSuiteName configuration value as name-attribute for run and root Assembly test-suite' {