Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String formatting panic fix #987

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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