Validate parses all literal format strings and type checks the format clause against the argument at the corresponding ordinal within the list literal argument to the function, if one is specified.
(env *cel.Env, _ cel.ValidatorConfig, a *ast.AST, iss *cel.Issues)
| 422 | // Validate parses all literal format strings and type checks the format clause against the argument |
| 423 | // at the corresponding ordinal within the list literal argument to the function, if one is specified. |
| 424 | func (v stringFormatValidatorV2) Validate(env *cel.Env, _ cel.ValidatorConfig, a *ast.AST, iss *cel.Issues) { |
| 425 | root := ast.NavigateAST(a) |
| 426 | formatCallExprs := ast.MatchDescendants(root, matchConstantFormatStringWithListLiteralArgs(a)) |
| 427 | for _, e := range formatCallExprs { |
| 428 | call := e.AsCall() |
| 429 | formatStr := call.Target().AsLiteral().Value().(string) |
| 430 | args := call.Args()[0].AsList().Elements() |
| 431 | formatCheck := &stringFormatCheckerV2{ |
| 432 | args: args, |
| 433 | ast: a, |
| 434 | } |
| 435 | // use a placeholder locale, since locale doesn't affect syntax |
| 436 | _, err := parseFormatStringV2(formatStr, formatCheck, formatCheck, v.maxPrecision) |
| 437 | if err != nil { |
| 438 | iss.ReportErrorAtID(getErrorExprID(e.ID(), err), "%v", err) |
| 439 | continue |
| 440 | } |
| 441 | seenArgs := formatCheck.argsRequested |
| 442 | if len(args) > seenArgs { |
| 443 | iss.ReportErrorAtID(e.ID(), |
| 444 | "too many arguments supplied to string.format (expected %d, got %d)", seenArgs, len(args)) |
| 445 | } |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | // stringFormatCheckerV2 implements the formatStringInterpolater interface |
| 450 | type stringFormatCheckerV2 struct { |
nothing calls this directly
no test coverage detected