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

Method Validate

cel/validator.go:450–481  ·  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

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