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