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

Method Validate

cel/validator.go:545–584  ·  view source on GitHub ↗
(e *Env, _ ValidatorConfig, a *ast.AST, iss *Issues)

Source from the content-addressed store, hash-verified

543}
544
545func (v regexProgramSizeLimitValidator) Validate(e *Env, _ ValidatorConfig, a *ast.AST, iss *Issues) {
546 if v.limit <= 0 {
547 return
548 }
549 root := ast.NavigateAST(a)
550 callExprs := ast.MatchDescendants(root, ast.KindMatcher(ast.CallKind))
551 for _, call := range callExprs {
552 c := call.AsCall()
553 fn := c.FunctionName()
554 if !isRegexFunctionName(fn) {
555 continue
556 }
557 args := c.Args()
558 var regexArgIndex int
559 if (fn == overloads.Matches || fn == "matches") && c.Target() != nil {
560 regexArgIndex = 0
561 } else {
562 regexArgIndex = 1
563 }
564 if len(args) <= regexArgIndex {
565 continue
566 }
567 arg := args[regexArgIndex]
568 if arg.Kind() != ast.LiteralKind {
569 continue
570 }
571 pattern, ok := arg.AsLiteral().Value().(string)
572 if !ok {
573 continue
574 }
575 sz, err := types.RegexProgramSize(pattern)
576 if err != nil {
577 // Invalid regex literals are handled in a different validator.
578 continue
579 }
580 if sz > v.limit {
581 iss.ReportErrorAtID(arg.ID(), "regex program size %d exceeds limit of %d", sz, v.limit)
582 }
583 }
584}
585
586func isEmptyRangeComprehension(e ast.NavigableExpr) bool {
587 if e.Kind() != ast.ComprehensionKind {

Callers

nothing calls this directly

Calls 14

NavigateASTFunction · 0.92
MatchDescendantsFunction · 0.92
KindMatcherFunction · 0.92
RegexProgramSizeFunction · 0.92
isRegexFunctionNameFunction · 0.85
AsCallMethod · 0.65
FunctionNameMethod · 0.65
ArgsMethod · 0.65
TargetMethod · 0.65
KindMethod · 0.65
ValueMethod · 0.65
AsLiteralMethod · 0.65

Tested by

no test coverage detected