MCPcopy Create free account
hub / github.com/cel-expr/cel-go / Validate

Method Validate

cel/validator.go:453–484  ·  view source on GitHub ↗

Validate implements the ASTValidator interface method.

(e *Env, _ ValidatorConfig, a *ast.AST, iss *Issues)

Source from the content-addressed store, hash-verified

451
452// Validate implements the ASTValidator interface method.
453func (v nestingLimitValidator) Validate(e *Env, _ ValidatorConfig, a *ast.AST, iss *Issues) {
454 root := ast.NavigateAST(a)
455 comprehensions := ast.MatchDescendants(root, ast.KindMatcher(ast.ComprehensionKind))
456 if len(comprehensions) <= v.limit {
457 return
458 }
459 for _, comp := range comprehensions {
460 count := 0
461 e := comp
462 hasParent := true
463 for hasParent {
464 // When the expression is not a comprehension, continue to the next ancestor.
465 if e.Kind() != ast.ComprehensionKind {
466 e, hasParent = e.Parent()
467 continue
468 }
469 // When the comprehension has an empty range, continue to the next ancestor
470 // as this comprehension does not have any associated cost.
471 if isEmptyRangeComprehension(e) {
472 e, hasParent = e.Parent()
473 continue
474 }
475 // Otherwise check the nesting limit.
476 count++
477 if count > v.limit {
478 iss.ReportErrorAtID(comp.ID(), "comprehension exceeds nesting limit")
479 break
480 }
481 e, hasParent = e.Parent()
482 }
483 }
484}
485
486type bindNestingLimitValidator struct {
487 limit int

Callers

nothing calls this directly

Calls 8

NavigateASTFunction · 0.92
MatchDescendantsFunction · 0.92
KindMatcherFunction · 0.92
KindMethod · 0.65
ParentMethod · 0.65
ReportErrorAtIDMethod · 0.65
IDMethod · 0.65

Tested by

no test coverage detected