mirror of
https://github.com/golang/go
synced 2024-11-24 02:30:12 -07:00
text/template: need to validate type when an argument is a function call
Missed a case; just need to call validateType. Fixes #10800. Change-Id: I81997ca7a9feb1be31c8b47e631b32712d7ffb86 Reviewed-on: https://go-review.googlesource.com/10031 Reviewed-by: Andrew Gerrand <adg@golang.org>
This commit is contained in:
parent
ecfe42cab0
commit
92bdbb8a3c
@ -660,7 +660,7 @@ func (s *state) evalArg(dot reflect.Value, typ reflect.Type, n parse.Node) refle
|
|||||||
case *parse.PipeNode:
|
case *parse.PipeNode:
|
||||||
return s.validateType(s.evalPipeline(dot, arg), typ)
|
return s.validateType(s.evalPipeline(dot, arg), typ)
|
||||||
case *parse.IdentifierNode:
|
case *parse.IdentifierNode:
|
||||||
return s.evalFunction(dot, arg, arg, nil, zero)
|
return s.validateType(s.evalFunction(dot, arg, arg, nil, zero), typ)
|
||||||
case *parse.ChainNode:
|
case *parse.ChainNode:
|
||||||
return s.validateType(s.evalChainNode(dot, arg, nil, zero), typ)
|
return s.validateType(s.evalChainNode(dot, arg, nil, zero), typ)
|
||||||
}
|
}
|
||||||
|
@ -531,6 +531,8 @@ var execTests = []execTest{
|
|||||||
{"bug14a", "{{(nil).True}}", "", tVal, false},
|
{"bug14a", "{{(nil).True}}", "", tVal, false},
|
||||||
{"bug14b", "{{$x := nil}}{{$x.anything}}", "", tVal, false},
|
{"bug14b", "{{$x := nil}}{{$x.anything}}", "", tVal, false},
|
||||||
{"bug14c", `{{$x := (1.0)}}{{$y := ("hello")}}{{$x.anything}}{{$y.true}}`, "", tVal, false},
|
{"bug14c", `{{$x := (1.0)}}{{$y := ("hello")}}{{$x.anything}}{{$y.true}}`, "", tVal, false},
|
||||||
|
// Didn't call validateType on function results. Issue 10800.
|
||||||
|
{"bug15", "{{valueString returnInt}}", "", tVal, false},
|
||||||
}
|
}
|
||||||
|
|
||||||
func zeroArgs() string {
|
func zeroArgs() string {
|
||||||
@ -570,6 +572,11 @@ func valueString(v string) string {
|
|||||||
return "value is ignored"
|
return "value is ignored"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// returnInt returns an int
|
||||||
|
func returnInt() int {
|
||||||
|
return 7
|
||||||
|
}
|
||||||
|
|
||||||
func add(args ...int) int {
|
func add(args ...int) int {
|
||||||
sum := 0
|
sum := 0
|
||||||
for _, x := range args {
|
for _, x := range args {
|
||||||
@ -611,6 +618,7 @@ func testExecute(execTests []execTest, template *Template, t *testing.T) {
|
|||||||
"makemap": makemap,
|
"makemap": makemap,
|
||||||
"mapOfThree": mapOfThree,
|
"mapOfThree": mapOfThree,
|
||||||
"oneArg": oneArg,
|
"oneArg": oneArg,
|
||||||
|
"returnInt": returnInt,
|
||||||
"stringer": stringer,
|
"stringer": stringer,
|
||||||
"typeOf": typeOf,
|
"typeOf": typeOf,
|
||||||
"valueString": valueString,
|
"valueString": valueString,
|
||||||
|
Loading…
Reference in New Issue
Block a user