Separate Where-Object comparison parameters and reject malformed native selectors
This commit is contained in:
@@ -4,8 +4,9 @@ New-Item -ItemType Directory -Path $EvidenceDir -Force|Out-Null
|
||||
if(!$Sources){$Sources=@(Get-ChildItem $PSScriptRoot -Filter '*.ps1'|Select-Object -ExpandProperty FullName)}
|
||||
$results=@(foreach($source in $Sources){
|
||||
$errors=$null
|
||||
[Management.Automation.Language.Parser]::ParseFile($source,[ref]$null,[ref]$errors)|Out-Null
|
||||
@{source=$source;passed=($errors.Count-eq0);errors=@($errors|Select-Object ErrorId,Message,@{n='line';e={$_.Extent.StartLineNumber}})}
|
||||
$ast=[Management.Automation.Language.Parser]::ParseFile($source,[ref]$null,[ref]$errors)
|
||||
$malformed=@($ast.FindAll({param($n)$n-is[Management.Automation.Language.CommandParameterAst]-and$n.ParameterName-match'^(eq|ne|gt|lt|ge|le)\d+$'},$true)|ForEach-Object{$_.Extent.Text})
|
||||
@{source=$source;passed=($errors.Count-eq0-and$malformed.Count-eq0);malformedOperatorParameters=$malformed;errors=@($errors|Select-Object ErrorId,Message,@{n='line';e={$_.Extent.StartLineNumber}})}
|
||||
})
|
||||
$passed=$results.Count-gt0-and@($results|Where-Object passed -ne $true).Count-eq0
|
||||
@{passed=$passed;checks=$results}|ConvertTo-Json -Depth 8|Set-Content (Join-Path $EvidenceDir 'syntax-result.json')
|
||||
|
||||
Reference in New Issue
Block a user