Skip to content

Commit 9b66ee1

Browse files
author
James Brundage
committed
ValidateScriptBlock: Returning true if not a [ScriptBlock] (#125)
1 parent 4d4b31a commit 9b66ee1

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Transpilers/Parameters/ValidateScriptBlock.psx.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ $validateScripts = @(
6969
if ($DataLanguage) {
7070
@'
7171
[ValidateScript({
72+
if ($_ -isnot [ScriptBlock]) { return $true }
7273
$sbCopy = "data { $_ }"
7374
try {
7475
$dataOutput = & ([ScriptBlock]::Create($sbCopy))
@@ -82,6 +83,7 @@ $validateScripts = @(
8283
if ($ParameterOnly) {
8384
@'
8485
[ValidateScript({
86+
if ($_ -isnot [ScriptBlock]) { return $true }
8587
$statementCount = 0
8688
$statementCount += $_.Ast.DynamicParamBlock.Statements.Count
8789
$statementCount += $_.Ast.BeginBlock.Statements.Count
@@ -98,6 +100,7 @@ $validateScripts = @(
98100
if ($NoBlock) {
99101
@'
100102
[ValidateScript({
103+
if ($_ -isnot [ScriptBlock]) { return $true }
101104
if ($_.Ast.DynamicParamBlock -or $_.Ast.BeginBlock -or $_.Ast.ProcessBlock) {
102105
throw "ScriptBlock should not have any named blocks"
103106
}
@@ -108,6 +111,7 @@ $validateScripts = @(
108111
if ($NoParameter) {
109112
@'
110113
[ValidateScript({
114+
if ($_ -isnot [ScriptBlock]) { return $true }
111115
if ($_.Ast.ParamBlock.Parameters.Count) {
112116
throw "ScriptBlock should not have parameters"
113117
}

0 commit comments

Comments
 (0)