Skip to content

Commit 64d2d7b

Browse files
committed
Allow nested interpolation
1 parent eb263c3 commit 64d2d7b

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

exec/exec.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,12 @@ import (
5454

5555
// Interpolate substitutes the params with the corresponding options
5656
func Interpolate(pattern string, opts map[string]string) (interpolated []string, err error) {
57-
for key, value := range opts {
58-
pattern = strings.Replace(pattern, "{"+key+"}", value, -1)
57+
oldPattern := ""
58+
for pattern != oldPattern {
59+
oldPattern = pattern
60+
for key, value := range opts {
61+
pattern = strings.Replace(pattern, "{"+key+"}", value, -1)
62+
}
5963
}
6064

6165
z, err := shellwords.Parse(pattern)

exec/exec_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,18 @@ func TestLocal(t *testing.T) {
8787
"",
8888
nil,
8989
},
90+
{
91+
"nested interpolation",
92+
"echo {interpolate.string}",
93+
map[string]string{
94+
"greeting": "hello",
95+
"target": "world",
96+
"interpolate.string": "{greeting} {target}",
97+
},
98+
"hello world",
99+
"",
100+
nil,
101+
},
90102
{
91103
"inject ; to perform other commands has no effect",
92104
"echo {interpolate.string}",

0 commit comments

Comments
 (0)