validateExpressionContent validates the content inside ${{ }}
(expr string, fullGroup string)
| 114 | |
| 115 | // validateExpressionContent validates the content inside ${{ }} |
| 116 | func validateExpressionContent(expr string, fullGroup string) error { |
| 117 | // Check for unbalanced parentheses |
| 118 | parenCount := 0 |
| 119 | for i, ch := range expr { |
| 120 | switch ch { |
| 121 | case '(': |
| 122 | parenCount++ |
| 123 | case ')': |
| 124 | parenCount-- |
| 125 | if parenCount < 0 { |
| 126 | return NewValidationError( |
| 127 | "expression", |
| 128 | "unbalanced parentheses in expression", |
| 129 | fmt.Sprintf("found closing ')' without matching opening '(' at position %d in expression: %s", i, expr), |
| 130 | "Ensure all parentheses are properly balanced in your expression.", |
| 131 | ) |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | if parenCount > 0 { |
| 137 | return NewValidationError( |
| 138 | "expression", |
| 139 | "unclosed parentheses in expression", |
| 140 | fmt.Sprintf("found %d unclosed opening '(' in expression: %s", parenCount, expr), |
| 141 | "Add the missing closing ')' to balance parentheses in your expression.", |
| 142 | ) |
| 143 | } |
| 144 | |
| 145 | // Check for unbalanced quotes (single, double, backtick) |
| 146 | if err := validateBalancedQuotes(expr); err != nil { |
| 147 | return err |
| 148 | } |
| 149 | |
| 150 | // Try to parse complex expressions with logical operators |
| 151 | if containsLogicalOperators(expr) { |
| 152 | expressionValidationLog.Print("Expression contains logical operators, performing deep validation") |
| 153 | if _, err := ParseExpression(expr); err != nil { |
| 154 | expressionValidationLog.Printf("Expression parsing failed: %v", err) |
| 155 | return NewValidationError( |
| 156 | "expression", |
| 157 | "invalid expression syntax", |
| 158 | "failed to parse expression: "+err.Error(), |
| 159 | "Fix the syntax error in your expression. Full expression: "+fullGroup, |
| 160 | ) |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | return nil |
| 165 | } |
| 166 | |
| 167 | // validateBalancedQuotes checks for balanced quotes in an expression |
| 168 | func validateBalancedQuotes(expr string) error { |