Skip to content

Commit badfce0

Browse files
Fix panic in formatting string for non-literal formats (#987)
1 parent 9e64eb7 commit badfce0

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

ext/formatting.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ func matchConstantFormatStringWithListLiteralArgs(a *ast.AST) ast.ExprMatcher {
484484
}
485485
}
486486
formatString := call.Target()
487-
if formatString.Kind() != ast.LiteralKind && formatString.AsLiteral().Type() != cel.StringType {
487+
if formatString.Kind() != ast.LiteralKind || formatString.AsLiteral().Type() != cel.StringType {
488488
return false
489489
}
490490
args := call.Args()

ext/strings_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ var stringTests = []struct {
141141
{expr: `strings.quote("\U0001F431\U0001F600\U0001F61B") == "\"\U0001F431\U0001F600\U0001F61B\""`},
142142
{expr: `strings.quote("ta©o©αT") == "\"ta©o©αT\""`},
143143
{expr: `strings.quote("") == "\"\""`},
144+
// Format tests with a non-literal as the format string
145+
{
146+
expr: `strings.quote('%s %s').format(['hello', 'world']) == "\"hello world\""`,
147+
},
144148
// Error test cases based on checked expression usage.
145149
{
146150
expr: `'tacocat'.charAt(30) == ''`,

0 commit comments

Comments
 (0)