From c61cf5f5e8d4bc6dfda5ec32fd92b74e5775010f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Mon, 1 Jul 2024 14:36:05 +0200 Subject: [PATCH] Powershell 5 does not have unicode escape --- src/functions/TestResults.NUnit3.ps1 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/functions/TestResults.NUnit3.ps1 b/src/functions/TestResults.NUnit3.ps1 index 3b996432c..75db6f9cc 100644 --- a/src/functions/TestResults.NUnit3.ps1 +++ b/src/functions/TestResults.NUnit3.ps1 @@ -1,5 +1,7 @@ # NUnit3 schema docs: https://docs.nunit.org/articles/nunit/technical-notes/usage/Test-Result-XML-Format.html +[char[]] $script:invalidCDataChars = foreach ($ch in (0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x0B, 0x0C, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F)) { [char]$ch } + function Write-NUnit3Report([Pester.Run] $Result, [System.Xml.XmlWriter] $XmlWriter) { # Write the XML Declaration $XmlWriter.WriteStartDocument($false) @@ -542,7 +544,6 @@ function Write-NUnit3OutputElement ($Output, [System.Xml.XmlWriter] $XmlWriter) # We convert each of these using the unicode printable version, # which is obtained by adding 0x2400 [int]$unicodeControlPictures = 0x2400 - [char[]] $invalidChars = "`u{0001}`u{0002}`u{0003}`u{0004}`u{0005}`u{0006}`u{0007}`u{0008}`u{000B}`u{000C}`u{000E}`u{000F}`u{0010}`u{0011}`u{0012}`u{0013}`u{0014}`u{0015}`u{0016}`u{0017}`u{0018}`u{0019}`u{001A}`u{001B}`u{001C}`u{001D}`u{001E}`u{001F}" # Avoid indexing into an enumerable, such as a `string`, when there is only one item in the # output array. @@ -552,7 +553,7 @@ function Write-NUnit3OutputElement ($Output, [System.Xml.XmlWriter] $XmlWriter) # The input is array of objects, convert them to strings. $line = if ($null -eq $out[$i]) { [String]::Empty } else { $out[$i].ToString() } - if (0 -gt $line.IndexOfAny($invalidChars)) { + if (0 -gt $line.IndexOfAny($script:invalidCDataChars)) { # No special chars that need replacing. $line } @@ -561,7 +562,7 @@ function Write-NUnit3OutputElement ($Output, [System.Xml.XmlWriter] $XmlWriter) $charCount = $chars.Length for ($j = 0; $j -lt $charCount; $j++) { $char = $chars[$j] - if ($char -in $invalidChars) { + if ($char -in $script:invalidCDataChars) { $chars[$j] = [char]([int]$char + $unicodeControlPictures) } }