From 044db6e8a2bbec5ccbf34d426fe1d5c316c4d618 Mon Sep 17 00:00:00 2001 From: Kelvin Smith Date: Sun, 8 Dec 2024 12:53:42 +1300 Subject: [PATCH] FIX: Use Max math function to ensure actionNames less than 5 characters are valid. --- src/Helper.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Helper.ps1 b/src/Helper.ps1 index d4bf2cd..4a99682 100644 --- a/src/Helper.ps1 +++ b/src/Helper.ps1 @@ -187,12 +187,12 @@ Function Sort-Action { $indexNumber++ } # Current error is that there can be an newly created action that does not have a parent property.??? - elseif (($null -ne $currentAction.Parent) -and ($Actions | Where-Object { $_.RunAfter -eq $(('{0}-False') -f $(($currentAction.Parent).Substring(0, ($currentAction.Parent).length - 5))) } )) { - $Actions | Where-Object { $_.RunAfter -eq $(('{0}-False') -f $(($currentAction.Parent).Substring(0, ($currentAction.Parent).length - 5))) } | + elseif (($null -ne $currentAction.Parent) -and ($Actions | Where-Object { $_.RunAfter -eq $(('{0}-False') -f $(($currentAction.Parent).Substring(0, [math]::max(1,($currentAction.Parent).length - 5)))) } )) { + $Actions | Where-Object { $_.RunAfter -eq $(('{0}-False') -f $(($currentAction.Parent).Substring(0, [math]::max(1,($currentAction.Parent).length - 5)))) } | Add-Member -MemberType NoteProperty -Name Order -Value $indexNumber # Fix the issue when currentAction is empty - if ($Actions | Where-Object { $_.RunAfter -eq $(('{0}-False') -f $(($currentAction.Parent).Substring(0, ($currentAction.Parent).length - 5))) }) { - $currentAction = $Actions | Where-Object { $_.RunAfter -eq $(('{0}-False') -f $(($currentAction.Parent).Substring(0, ($currentAction.Parent).length - 5))) } + if ($Actions | Where-Object { $_.RunAfter -eq $(('{0}-False') -f $(($currentAction.Parent).Substring(0, [math]::max(1,($currentAction.Parent).length - 5)))) }) { + $currentAction = $Actions | Where-Object { $_.RunAfter -eq $(('{0}-False') -f $(($currentAction.Parent).Substring(0, [math]::max(1,($currentAction.Parent).length - 5)))) } } # Increment the indexNumber $indexNumber++