Skip to content

Commit b5ad499

Browse files
authored
fix: environment variables should be expanded when ws dir prefix x is used (#317)
Small fix that prevents environment variable for directory / file path fields. When `//` is used as a prefix, expansion was previously being skipped.
1 parent e51df0c commit b5ad499

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

internal/utils/utils.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,11 @@ func ExpandPath(path, fallbackDir string, env map[string]string) string {
7171
// - all other paths -> delegated to ExpandPath
7272
// If the input contains a filename, returns just the directory portion.
7373
func ExpandDirectory(dir, wsPath, execPath string, env map[string]string) string {
74-
var expandedPath string
74+
expandedPath := dir
7575
if wsPath != "" && strings.HasPrefix(dir, "//") {
76-
expandedPath = strings.Replace(dir, "//", wsPath+"/", 1)
77-
} else {
78-
expandedPath = ExpandPath(dir, filepath.Dir(execPath), env)
76+
expandedPath = strings.Replace(expandedPath, "//", wsPath+"/", 1)
7977
}
78+
expandedPath = ExpandPath(expandedPath, filepath.Dir(execPath), env)
8079

8180
if ext := filepath.Ext(expandedPath); ext != "" && !isHiddenDir(expandedPath) {
8281
return filepath.Dir(expandedPath)

internal/utils/utils_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ var _ = Describe("Utils", func() {
6262
Expect(utils.ExpandDirectory("/${VAR1}/${VAR2}", wsDir, execPath, envMap)).
6363
To(Equal("/one/two"))
6464
})
65+
It("expands the env vars with a ws prefix", func() {
66+
envMap := map[string]string{"VAR1": "one"}
67+
Expect(utils.ExpandDirectory("//dir/${VAR1}", wsDir, execPath, envMap)).
68+
To(Equal("/workspace/dir/one"))
69+
})
6570
It("logs a warning if the env var is not found", func() {
6671
envMap := map[string]string{"VAR1": "one"}
6772
mockLogger.EXPECT().Warnx("unable to find env key in path expansion", "key", "VAR2")

0 commit comments

Comments
 (0)