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

Method Validate

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

413
414// Validate implements the ASTValidator interface method.
415func (v nestingLimitValidator) Validate(e *Env, _ ValidatorConfig, a *ast.AST, iss *Issues) {
416 root := ast.NavigateAST(a)
417 comprehensions := ast.MatchDescendants(root, ast.KindMatcher(ast.ComprehensionKind))
418 if len(comprehensions) <= v.limit {
419 return
420 }
421 for _, comp := range comprehensions {
422 count := 0
423 e := comp
424 hasParent := true
425 for hasParent {
426 // When the expression is not a comprehension, continue to the next ancestor.
427 if e.Kind() != ast.ComprehensionKind {
428 e, hasParent = e.Parent()
429 continue
430 }
431 // When the comprehension has an empty range, continue to the next ancestor
432 // as this comprehension does not have any associated cost.
433 iterRange := e.AsComprehension().IterRange()
434 if iterRange.Kind() == ast.ListKind && iterRange.AsList().Size() == 0 {
435 e, hasParent = e.Parent()
436 continue
437 }
438 // Otherwise check the nesting limit.
439 count++
440 if count > v.limit {
441 iss.ReportErrorAtID(comp.ID(), "comprehension exceeds nesting limit")
442 break
443 }
444 e, hasParent = e.Parent()
445 }
446 }
447}

Callers

nothing calls this directly

Calls 11

NavigateASTFunction · 0.92
MatchDescendantsFunction · 0.92
KindMatcherFunction · 0.92
KindMethod · 0.65
ParentMethod · 0.65
IterRangeMethod · 0.65
AsComprehensionMethod · 0.65
SizeMethod · 0.65
AsListMethod · 0.65
ReportErrorAtIDMethod · 0.65
IDMethod · 0.65

Tested by

no test coverage detected