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)
| 430 | // Validate parses all literal format strings and type checks the format clause against the argument |
| 431 | // at the corresponding ordinal within the list literal argument to the function, if one is specified. |
| 432 | func (v stringFormatValidator) Validate(env *cel.Env, _ cel.ValidatorConfig, a *ast.AST, iss *cel.Issues) { |
| 433 | root := ast.NavigateAST(a) |
| 434 | formatCallExprs := ast.MatchDescendants(root, matchConstantFormatStringWithListLiteralArgs(a)) |
| 435 | for _, e := range formatCallExprs { |
| 436 | call := e.AsCall() |
| 437 | formatStr := call.Target().AsLiteral().Value().(string) |
| 438 | args := call.Args()[0].AsList().Elements() |
| 439 | formatCheck := &stringFormatChecker{ |
| 440 | args: args, |
| 441 | ast: a, |
| 442 | } |
| 443 | // use a placeholder locale, since locale doesn't affect syntax |
| 444 | _, err := parseFormatString(formatStr, formatCheck, formatCheck, "en_US", v.maxPrecision) |
| 445 | if err != nil { |
| 446 | iss.ReportErrorAtID(getErrorExprID(e.ID(), err), "%v", err) |
| 447 | continue |
| 448 | } |
| 449 | seenArgs := formatCheck.argsRequested |
| 450 | if len(args) > seenArgs { |
| 451 | iss.ReportErrorAtID(e.ID(), |
| 452 | "too many arguments supplied to string.format (expected %d, got %d)", seenArgs, len(args)) |
| 453 | } |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | // getErrorExprID determines which list literal argument triggered a type-disagreement for the |
| 458 | // purposes of more accurate error message reports. |
nothing calls this directly
no test coverage detected