| 563 | } |
| 564 | |
| 565 | func (c *stringFormatCheckerV2) verifyString(sub ast.Expr) (bool, int64) { |
| 566 | paramA := cel.TypeParamType("A") |
| 567 | paramB := cel.TypeParamType("B") |
| 568 | subVerified := c.verifyTypeOneOf(sub.ID(), |
| 569 | cel.ListType(paramA), cel.MapType(paramA, paramB), |
| 570 | cel.IntType, cel.UintType, cel.DoubleType, cel.BoolType, cel.StringType, |
| 571 | cel.TimestampType, cel.BytesType, cel.DurationType, cel.TypeType, cel.NullType) |
| 572 | if !subVerified { |
| 573 | return false, sub.ID() |
| 574 | } |
| 575 | switch sub.Kind() { |
| 576 | case ast.ListKind: |
| 577 | for _, e := range sub.AsList().Elements() { |
| 578 | // recursively verify if we're dealing with a list/map |
| 579 | verified, id := c.verifyString(e) |
| 580 | if !verified { |
| 581 | return false, id |
| 582 | } |
| 583 | } |
| 584 | return true, sub.ID() |
| 585 | case ast.MapKind: |
| 586 | for _, e := range sub.AsMap().Entries() { |
| 587 | // recursively verify if we're dealing with a list/map |
| 588 | entry := e.AsMapEntry() |
| 589 | verified, id := c.verifyString(entry.Key()) |
| 590 | if !verified { |
| 591 | return false, id |
| 592 | } |
| 593 | verified, id = c.verifyString(entry.Value()) |
| 594 | if !verified { |
| 595 | return false, id |
| 596 | } |
| 597 | } |
| 598 | return true, sub.ID() |
| 599 | default: |
| 600 | return true, sub.ID() |
| 601 | } |
| 602 | } |
| 603 | |
| 604 | // helper routines for reporting common errors during string formatting static validation and |
| 605 | // runtime execution. |