From d9c9beba7fa3c556ab70f0372f64eb058ee7f0dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Samin?= Date: Mon, 9 Apr 2018 15:45:30 +0200 Subject: [PATCH] fix(api): interpolate should not be replaced git.branch as git__branch (#2553) --- sdk/interpolate/interpolate.go | 8 +++++++- sdk/interpolate/interpolate_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/sdk/interpolate/interpolate.go b/sdk/interpolate/interpolate.go index 3b30960a18..def2797863 100644 --- a/sdk/interpolate/interpolate.go +++ b/sdk/interpolate/interpolate.go @@ -48,7 +48,13 @@ func Do(input string, vars map[string]string) (string, error) { if v == "" { empty[k] = k } - input = strings.Replace(input, k, kb, -1) + //The key should be used as a variable to be replaced + kAsVar := "{{." + k + kbAsVar := "{{." + kb + input = strings.Replace(input, kAsVar, kbAsVar, -1) + kAsVar = "{{. " + k + kbAsVar = "{{. " + kb + input = strings.Replace(input, kAsVar, kbAsVar, -1) } var helper string diff --git a/sdk/interpolate/interpolate_test.go b/sdk/interpolate/interpolate_test.go index 694aa97f2d..4b5e48795a 100644 --- a/sdk/interpolate/interpolate_test.go +++ b/sdk/interpolate/interpolate_test.go @@ -268,6 +268,33 @@ func TestDo(t *testing.T) { }, want: `{"HOST": "customermyprefix.lb"}`, }, + { + name: "git.branch in payload should not be interpolated", + args: args{ + input: ` +name: "w{{.cds.pip.docker.image}}-generated" +version: v1.0 +workflow: + build-go: + pipeline: build-go-generated + payload: + git.author: "" + git.branch: master`, + vars: map[string]string{ + "git.branch": "master", + "git.author": "", + }, + }, + want: ` +name: "w{{.cds.pip.docker.image}}-generated" +version: v1.0 +workflow: + build-go: + pipeline: build-go-generated + payload: + git.author: "" + git.branch: master`, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {