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

Method Validate

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

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