Skip to content

Commit 48ea9d0

Browse files
alexandairCopilot
andauthored
35039 - Fix to enhance JSON parsing to skip non-JSON scalar values (#903)
* 35039 - Fix to enhance JSON parsing to skip non-JSON scalar values and ensure only valid object/array payloads are processed * Update src/powershell/tests/Test-Assessment.35039.ps1 Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/powershell/tests/Test-Assessment.35039.ps1 Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 3a72165 commit 48ea9d0

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

src/powershell/tests/Test-Assessment.35039.ps1

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,17 @@ function Test-Assessment-35039 {
5757
if ($ruleXml.root) {
5858
$valueElements = $ruleXml.root.GetElementsByTagName('value')
5959
foreach ($valueElement in $valueElements) {
60-
if (-not [string]::IsNullOrWhiteSpace($valueElement.'#text')) {
60+
$rawValue = $valueElement.'#text'
61+
if (-not [string]::IsNullOrWhiteSpace($rawValue)) {
6162
try {
62-
$jsonData = $valueElement.'#text' | ConvertFrom-Json
63+
$jsonText = $rawValue.Trim()
64+
65+
# We only need object/array JSON payloads that can contain Workloads
66+
if ($jsonText -notmatch '^[\{\[]') {
67+
continue
68+
}
69+
70+
$jsonData = $jsonText | ConvertFrom-Json -ErrorAction Stop
6371
if ($jsonData.Workloads -and $jsonData.Workloads -contains 'Copilot') {
6472
$hasCopilotConfig = $true
6573
break

0 commit comments

Comments
 (0)