Skip to content

Commit

Permalink
fix case sensitivity on check for format() calls
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Oct 25, 2024
1 parent 32023b2 commit 1c23560
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions expr_insecure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,14 @@ func TestExprInsecureDetectUntrustedValue(t *testing.T) {
},
},
testCase{
"format('{} {}', github.event.pages.*.page_name, github.event.issue.title)",
"format('{0} {1}', github.event.pages.*.page_name, github.event.issue.title)",
[]string{
"github.event.pages.*.page_name",
"github.event.issue.title",
},
},
testCase{
"format('{} {}', github.event.*.body, github.event.*.*)",
"format('{0} {1}', github.event.*.body, github.event.*.*)",
[]string{
"github.event.",
"github.event.",
Expand Down
4 changes: 2 additions & 2 deletions expr_sema.go
Original file line number Diff line number Diff line change
Expand Up @@ -786,11 +786,11 @@ func checkFuncSignature(n *FuncCallNode, sig *FuncSignature, args []ExprType) *E
return nil
}

func (sema *ExprSemanticsChecker) checkBuiltinFunctionCall(n *FuncCallNode, sig *FuncSignature) {
func (sema *ExprSemanticsChecker) checkBuiltinFunctionCall(n *FuncCallNode, _ *FuncSignature) {
sema.checkSpecialFunctionAvailability(n)

// Special checks for specific built-in functions
switch n.Callee {
switch strings.ToLower(n.Callee) {
case "format":
lit, ok := n.Args[0].(*StringNode)
if !ok {
Expand Down
9 changes: 8 additions & 1 deletion expr_sema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ func TestExprSemanticsCheckOK(t *testing.T) {
expected: StringType{},
},
{
what: "format() function arguments varlidation",
what: "format() function arguments validation",
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)",
expected: StringType{},
},
Expand Down Expand Up @@ -1016,6 +1016,13 @@ func TestExprSemanticsCheckError(t *testing.T) {
"takes at least 2 parameters but 1 arguments are given",
},
},
{
what: "function name of format() call check is case insensitive",
input: "Format('{0}', 1, 2)",
expected: []string{
`format string "{0}" does not contain placeholder {1}`,
},
},
{
what: "undefined matrix value",
input: "matrix.bar",
Expand Down

0 comments on commit 1c23560

Please sign in to comment.