Skip to content

Commit 1c23560

Browse files
committed
fix case sensitivity on check for format() calls
1 parent 32023b2 commit 1c23560

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

expr_insecure_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,14 @@ func TestExprInsecureDetectUntrustedValue(t *testing.T) {
195195
},
196196
},
197197
testCase{
198-
"format('{} {}', github.event.pages.*.page_name, github.event.issue.title)",
198+
"format('{0} {1}', github.event.pages.*.page_name, github.event.issue.title)",
199199
[]string{
200200
"github.event.pages.*.page_name",
201201
"github.event.issue.title",
202202
},
203203
},
204204
testCase{
205-
"format('{} {}', github.event.*.body, github.event.*.*)",
205+
"format('{0} {1}', github.event.*.body, github.event.*.*)",
206206
[]string{
207207
"github.event.",
208208
"github.event.",

expr_sema.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -786,11 +786,11 @@ func checkFuncSignature(n *FuncCallNode, sig *FuncSignature, args []ExprType) *E
786786
return nil
787787
}
788788

789-
func (sema *ExprSemanticsChecker) checkBuiltinFunctionCall(n *FuncCallNode, sig *FuncSignature) {
789+
func (sema *ExprSemanticsChecker) checkBuiltinFunctionCall(n *FuncCallNode, _ *FuncSignature) {
790790
sema.checkSpecialFunctionAvailability(n)
791791

792792
// Special checks for specific built-in functions
793-
switch n.Callee {
793+
switch strings.ToLower(n.Callee) {
794794
case "format":
795795
lit, ok := n.Args[0].(*StringNode)
796796
if !ok {

expr_sema_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ func TestExprSemanticsCheckOK(t *testing.T) {
495495
expected: StringType{},
496496
},
497497
{
498-
what: "format() function arguments varlidation",
498+
what: "format() function arguments validation",
499499
input: "format('{0}{0}{0} {1}{2}{1} {1}{2}{1}{2} {0} {1}{1}{1} {2}{2}{2} {0}{0}{0}{0} {0}', 1, 'foo', true)",
500500
expected: StringType{},
501501
},
@@ -1016,6 +1016,13 @@ func TestExprSemanticsCheckError(t *testing.T) {
10161016
"takes at least 2 parameters but 1 arguments are given",
10171017
},
10181018
},
1019+
{
1020+
what: "function name of format() call check is case insensitive",
1021+
input: "Format('{0}', 1, 2)",
1022+
expected: []string{
1023+
`format string "{0}" does not contain placeholder {1}`,
1024+
},
1025+
},
10191026
{
10201027
what: "undefined matrix value",
10211028
input: "matrix.bar",

0 commit comments

Comments
 (0)