From 89955d71ef426155b907808fa714210b1fa795c0 Mon Sep 17 00:00:00 2001 From: Eric Jenkins Date: Fri, 17 Jun 2022 13:50:02 -0400 Subject: [PATCH 1/3] added newline creation to raw xccdf --- CHANGELOG.md | 2 ++ source/Module/STIG/Convert/Functions.PowerStigXml.ps1 | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c843997f..42a876c04 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## [Unreleased] +* PowerSTIG Convert should add newline to raw Xccdf to ensure Pester tests Pass : [#1118](https://github.com/microsoft/PowerStig/issues/1118) + ## [4.13.0] - 2022-06-16 * Update PowerSTIG to successfully parse/apply Microsoft Windows 10 STIG - Ver 2, Rel 4: [#1096](https://github.com/microsoft/PowerStig/issues/1096) diff --git a/source/Module/STIG/Convert/Functions.PowerStigXml.ps1 b/source/Module/STIG/Convert/Functions.PowerStigXml.ps1 index ae58be69f..72166573e 100644 --- a/source/Module/STIG/Convert/Functions.PowerStigXml.ps1 +++ b/source/Module/STIG/Convert/Functions.PowerStigXml.ps1 @@ -249,6 +249,16 @@ function ConvertTo-PowerStigXml { $convertedStigObjects = ConvertFrom-StigXccdf -Path $Path -RuleIdFilter $RuleIdFilter + # Add a newline to end of raw xccdf if it doesn't exist + $rawXccdf = Get-Content -Path $Path + $fileLength = $rawXccdf.Length + $lastLine = $rawXccdf[$fileLength - 1] + + if ($lastline -ne "") + { + Add-Content $path '' + } + # Get the raw xccdf xml to pull additional details from the root node. [xml] $xccdfXml = Get-Content -Path $Path -Encoding UTF8 [version] $stigVersionNumber = Get-StigVersionNumber -StigDetails $xccdfXml From 4e8aef759549615fb384dfdad29e22ac6ca0bb0f Mon Sep 17 00:00:00 2001 From: Eric Jenkins Date: Fri, 17 Jun 2022 14:00:46 -0400 Subject: [PATCH 2/3] update based on feedback --- source/Module/STIG/Convert/Functions.PowerStigXml.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/Module/STIG/Convert/Functions.PowerStigXml.ps1 b/source/Module/STIG/Convert/Functions.PowerStigXml.ps1 index 72166573e..3a70f2313 100644 --- a/source/Module/STIG/Convert/Functions.PowerStigXml.ps1 +++ b/source/Module/STIG/Convert/Functions.PowerStigXml.ps1 @@ -254,7 +254,7 @@ function ConvertTo-PowerStigXml $fileLength = $rawXccdf.Length $lastLine = $rawXccdf[$fileLength - 1] - if ($lastline -ne "") + if ($lastline -ne '') { Add-Content $path '' } From 8210a796e6fa3d2e8d89663bceb1ae7eec5dfa16 Mon Sep 17 00:00:00 2001 From: Eric Jenkins Date: Fri, 17 Jun 2022 14:03:03 -0400 Subject: [PATCH 3/3] update based on feedback --- source/Module/STIG/Convert/Functions.PowerStigXml.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/Module/STIG/Convert/Functions.PowerStigXml.ps1 b/source/Module/STIG/Convert/Functions.PowerStigXml.ps1 index 3a70f2313..a24f3e865 100644 --- a/source/Module/STIG/Convert/Functions.PowerStigXml.ps1 +++ b/source/Module/STIG/Convert/Functions.PowerStigXml.ps1 @@ -256,7 +256,7 @@ function ConvertTo-PowerStigXml if ($lastline -ne '') { - Add-Content $path '' + Add-Content -Path $path -Value '' } # Get the raw xccdf xml to pull additional details from the root node.