Hardens the match interoplator against negative arguments.
This commit is contained in:
parent
63c826c2c0
commit
a9d640c024
|
@ -128,7 +128,7 @@ func (ct *CompiledTemplate) Render(name string) (*structs.PreparedQuery, error)
|
|||
Variadic: false,
|
||||
Callback: func(inputs []interface{}) (interface{}, error) {
|
||||
i, ok := inputs[0].(int)
|
||||
if ok && i < len(matches) {
|
||||
if ok && i >= 0 && i < len(matches) {
|
||||
return matches[i], nil
|
||||
} else {
|
||||
return "", nil
|
||||
|
|
|
@ -214,6 +214,7 @@ func TestTemplate_Render(t *testing.T) {
|
|||
Service: structs.ServiceQuery{
|
||||
Service: "${name.prefix} xxx ${name.full} xxx ${name.suffix}",
|
||||
Tags: []string{
|
||||
"${match(-1)}",
|
||||
"${match(0)}",
|
||||
"${match(1)}",
|
||||
"${match(2)}",
|
||||
|
@ -243,6 +244,7 @@ func TestTemplate_Render(t *testing.T) {
|
|||
Service: structs.ServiceQuery{
|
||||
Service: "hello- xxx hello-foo-bar-none xxx foo-bar-none",
|
||||
Tags: []string{
|
||||
"",
|
||||
"hello-foo-bar-none",
|
||||
"hello",
|
||||
"foo",
|
||||
|
@ -277,6 +279,7 @@ func TestTemplate_Render(t *testing.T) {
|
|||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"42",
|
||||
},
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue