Skip to content

Commit

Permalink
Fix panic in formatting string for non-literal formats (#987)
Browse files Browse the repository at this point in the history
  • Loading branch information
TristonianJones authored Jul 30, 2024
1 parent 9e64eb7 commit badfce0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ext/formatting.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ func matchConstantFormatStringWithListLiteralArgs(a *ast.AST) ast.ExprMatcher {
}
}
formatString := call.Target()
if formatString.Kind() != ast.LiteralKind && formatString.AsLiteral().Type() != cel.StringType {
if formatString.Kind() != ast.LiteralKind || formatString.AsLiteral().Type() != cel.StringType {
return false
}
args := call.Args()
Expand Down
4 changes: 4 additions & 0 deletions ext/strings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ var stringTests = []struct {
{expr: `strings.quote("\U0001F431\U0001F600\U0001F61B") == "\"\U0001F431\U0001F600\U0001F61B\""`},
{expr: `strings.quote("ta©o©αT") == "\"ta©o©αT\""`},
{expr: `strings.quote("") == "\"\""`},
// Format tests with a non-literal as the format string
{
expr: `strings.quote('%s %s').format(['hello', 'world']) == "\"hello world\""`,
},
// Error test cases based on checked expression usage.
{
expr: `'tacocat'.charAt(30) == ''`,
Expand Down

0 comments on commit badfce0

Please sign in to comment.