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

Method Validate

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

Source from the content-addressed store, hash-verified

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