Enhance configuration data validation and add new utility functions
- Added validation for empty values in Assert-ConfigurationDataParameter. - Introduced Assert-ConfigurationDataSecretReference for secret reference validation. - Implemented Test-ConfigurationDataExpressionParentheses to validate expression syntax. - Added Test-ConfigurationDataMissingReferenceError to check for missing parameter or variable definitions. - Updated Invoke-ConfigurationDataExpression to handle new validation logic. - Revised Readme.md to reflect changes in secret reference handling.
This commit is contained in:
39
Private/Test-ConfigurationDataExpressionParentheses.ps1
Normal file
39
Private/Test-ConfigurationDataExpressionParentheses.ps1
Normal file
@@ -0,0 +1,39 @@
|
||||
function Test-ConfigurationDataExpressionParentheses {
|
||||
[CmdletBinding()]
|
||||
Param(
|
||||
[AllowNull()]
|
||||
[string]
|
||||
$Expression
|
||||
)
|
||||
|
||||
if([string]::IsNullOrWhiteSpace($Expression)){
|
||||
return $true
|
||||
}
|
||||
|
||||
$Depth = 0
|
||||
$InString = $false
|
||||
|
||||
for($Index = 0; $Index -lt $Expression.Length; $Index++){
|
||||
$Character = $Expression[$Index]
|
||||
|
||||
if($Character -eq "'"){
|
||||
$InString = -not $InString
|
||||
continue
|
||||
}
|
||||
|
||||
if($InString){
|
||||
continue
|
||||
}
|
||||
|
||||
if($Character -eq "("){
|
||||
$Depth++
|
||||
}elseif($Character -eq ")"){
|
||||
$Depth--
|
||||
if($Depth -lt 0){
|
||||
return $false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $Depth -eq 0 -and -not $InString
|
||||
}
|
||||
Reference in New Issue
Block a user