From 38474fad116699a485c3a913e71feab123b3044b Mon Sep 17 00:00:00 2001 From: Monard Vong Date: Sun, 15 Sep 2019 23:08:44 +0200 Subject: [PATCH] Fix #691 - ADD does not understand ENV variables --- pkg/util/command_util.go | 3 ++- pkg/util/command_util_test.go | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/pkg/util/command_util.go b/pkg/util/command_util.go index 6d9471ebd..15ed41b18 100644 --- a/pkg/util/command_util.go +++ b/pkg/util/command_util.go @@ -65,7 +65,8 @@ func ResolveEnvironmentReplacementList(values, envs []string, isFilepath bool) ( func ResolveEnvironmentReplacement(value string, envs []string, isFilepath bool) (string, error) { shlex := shell.NewLex(parser.DefaultEscapeToken) fp, err := shlex.ProcessWord(value, envs) - if !isFilepath { + // Check after replacement if value is a remote URL + if !isFilepath || IsSrcRemoteFileURL(fp) { return fp, err } if err != nil { diff --git a/pkg/util/command_util_test.go b/pkg/util/command_util_test.go index 3e2342595..6f7aa01a7 100644 --- a/pkg/util/command_util_test.go +++ b/pkg/util/command_util_test.go @@ -97,6 +97,14 @@ var testEnvReplacement = []struct { }, expectedPath: "8080/udp", }, + { + path: "$url", + envs: []string{ + "url=http://example.com", + }, + isFilepath: true, + expectedPath: "http://example.com", + }, } func Test_EnvReplacement(t *testing.T) { @@ -472,15 +480,16 @@ func TestResolveEnvironmentReplacementList(t *testing.T) { name: "url", args: args{ values: []string{ - "https://google.com/$foo", "$bar", + "https://google.com/$foo", "$bar", "$url", }, envs: []string{ "foo=baz", "bar=bat", + "url=https://google.com", }, }, - want: []string{"https://google.com/baz", "bat"}, - }, + want: []string{"https://google.com/baz", "bat", "https://google.com"}, + }, { name: "mixed", args: args{