1
0
mirror of https://github.com/golang/go synced 2024-11-24 17:10:03 -07:00

text/template: avoid index-out-of-range panic when accessing args[0]

Fixes #70341

Change-Id: I3df0175929b4aed76522ef36aecfa924f3883d9e
This commit is contained in:
Jes Cok 2024-11-15 00:30:23 +08:00
parent 8e714281e4
commit 88d346a7ca
2 changed files with 14 additions and 7 deletions

View File

@ -855,7 +855,7 @@ func (s *state) evalCall(dot, fun reflect.Value, isBuiltin bool, node parse.Node
// Special case for the "call" builtin.
// Insert the name of the callee function as the first argument.
if isBuiltin && name == "call" {
if len(args) > 0 && isBuiltin && name == "call" {
calleeName := args[0].String()
argv = append([]reflect.Value{reflect.ValueOf(calleeName)}, argv...)
fun = reflect.ValueOf(call)

View File

@ -1779,7 +1779,14 @@ func TestFunctionCheckDuringCall(t *testing.T) {
input string
data any
wantErr string
}{{
}{
{
name: "call with no arguments",
input: `{{ 1 | call }}`,
data: tVal,
wantErr: "error calling call: unreachable",
},
{
name: "call nothing",
input: `{{call}}`,
data: tVal,