summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pkg/utils/template.go9
-rw-r--r--pkg/utils/template_test.go7
2 files changed, 13 insertions, 3 deletions
diff --git a/pkg/utils/template.go b/pkg/utils/template.go
index d98a68b99..9b7f544d1 100644
--- a/pkg/utils/template.go
+++ b/pkg/utils/template.go
@@ -22,9 +22,12 @@ func ResolveTemplate(templateStr string, object interface{}, funcs template.Func
// ResolvePlaceholderString populates a template with values
func ResolvePlaceholderString(str string, arguments map[string]string) string {
+ oldnews := make([]string, 0, len(arguments)*4)
for key, value := range arguments {
- str = strings.Replace(str, "{{"+key+"}}", value, -1)
- str = strings.Replace(str, "{{."+key+"}}", value, -1)
+ oldnews = append(oldnews,
+ "{{"+key+"}}", value,
+ "{{."+key+"}}", value,
+ )
}
- return str
+ return strings.NewReplacer(oldnews...).Replace(str)
}
diff --git a/pkg/utils/template_test.go b/pkg/utils/template_test.go
index f294d115d..236c23278 100644
--- a/pkg/utils/template_test.go
+++ b/pkg/utils/template_test.go
@@ -53,6 +53,13 @@ func TestResolvePlaceholderString(t *testing.T) {
},
"{{}} {{ this }} { should not throw}} an {{{{}}}} error",
},
+ {
+ "{{a}}",
+ map[string]string{
+ "a": "X{{.a}}X",
+ },
+ "X{{.a}}X",
+ },
}
for _, s := range scenarios {