Validate implements the ASTValidator interface method.
(e *Env, _ ValidatorConfig, a *ast.AST, iss *Issues)
| 514 | |
| 515 | // Validate implements the ASTValidator interface method. |
| 516 | func (v bindNestingLimitValidator) Validate(e *Env, _ ValidatorConfig, a *ast.AST, iss *Issues) { |
| 517 | root := ast.NavigateAST(a) |
| 518 | comprehensions := ast.MatchDescendants(root, ast.KindMatcher(ast.ComprehensionKind)) |
| 519 | var celBinds []ast.NavigableExpr |
| 520 | for _, comp := range comprehensions { |
| 521 | if isCelBind(comp) { |
| 522 | celBinds = append(celBinds, comp) |
| 523 | } |
| 524 | } |
| 525 | if len(celBinds) <= v.limit { |
| 526 | return |
| 527 | } |
| 528 | for _, comp := range celBinds { |
| 529 | count := 0 |
| 530 | e := comp |
| 531 | hasParent := true |
| 532 | for hasParent { |
| 533 | if isCelBind(e) { |
| 534 | count++ |
| 535 | if count > v.limit { |
| 536 | iss.ReportErrorAtID(comp.ID(), "cel.bind exceeds nesting limit") |
| 537 | break |
| 538 | } |
| 539 | } |
| 540 | e, hasParent = e.Parent() |
| 541 | } |
| 542 | } |
| 543 | } |
| 544 | |
| 545 | func (v regexProgramSizeLimitValidator) Validate(e *Env, _ ValidatorConfig, a *ast.AST, iss *Issues) { |
| 546 | if v.limit <= 0 { |
nothing calls this directly
no test coverage detected