From 682191f5233794448df73aae203a2d3f4f90932a Mon Sep 17 00:00:00 2001 From: nihilo Date: Fri, 9 Jul 2021 03:06:52 +0800 Subject: [PATCH] Bugfix/trailing path separator (#1683) * Test_EnvReplacement: env of path ends in a slash * Fix trailing path separator --- pkg/util/command_util.go | 5 +++-- pkg/util/command_util_test.go | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/pkg/util/command_util.go b/pkg/util/command_util.go index 4330d6060..615ef99fa 100644 --- a/pkg/util/command_util.go +++ b/pkg/util/command_util.go @@ -79,9 +79,10 @@ func ResolveEnvironmentReplacement(value string, envs []string, isFilepath bool) if err != nil { return "", err } + isDir := strings.HasSuffix(fp, pathSeparator) fp = filepath.Clean(fp) - if IsDestDir(value) && !IsDestDir(fp) { - fp = fp + "/" + if isDir && !strings.HasSuffix(fp, pathSeparator) { + fp = fp + pathSeparator } return fp, nil } diff --git a/pkg/util/command_util_test.go b/pkg/util/command_util_test.go index 616ad61e3..632ef2eb4 100644 --- a/pkg/util/command_util_test.go +++ b/pkg/util/command_util_test.go @@ -53,6 +53,14 @@ var testEnvReplacement = []struct { isFilepath: true, expectedPath: "/simple/path/", }, + { + path: "$simple", + envs: []string{ + "simple=/path/", + }, + isFilepath: true, + expectedPath: "/path/", + }, { path: "${a}/b", envs: []string{