Skip to content

Commit 2b50034

Browse files
fix(open): guard linux/darwin VS Code probes against empty HOME
When HOME was unset, filepath.Join produced relative per-user paths (.local/bin/code, Applications/Visual Studio Code.app) that could match an unintended binary or directory in the working directory. Skip those entries when HOME is empty.
1 parent 56611ce commit 2b50034

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

internal/tools/tool/vscode_darwin.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,16 @@ func (t *VSCode) searchLocations() []string {
2121
if build == "insiders" {
2222
app = "Visual Studio Code - Insiders.app"
2323
}
24-
locations = append(locations,
25-
filepath.Join("/", "Applications", app),
26-
filepath.Join(userProfile, "Applications", app),
27-
filepath.Join(userProfile, "Downloads", app),
28-
)
24+
locations = append(locations, filepath.Join("/", "Applications", app))
25+
// Skip the per-user paths when $HOME is empty -- filepath.Join would
26+
// produce a relative "Applications/..." that could match a directory
27+
// in the working directory.
28+
if userProfile != "" {
29+
locations = append(locations,
30+
filepath.Join(userProfile, "Applications", app),
31+
filepath.Join(userProfile, "Downloads", app),
32+
)
33+
}
2934
}
3035
return locations
3136
}

internal/tools/tool/vscode_linux.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,14 @@ func (t *VSCode) searchLocations() []string {
2323
}
2424
locations = append(locations,
2525
filepath.Join("/", "usr", "bin", cli),
26-
filepath.Join(userProfile, ".local", "bin", cli),
26+
)
27+
// Skip the per-user path when $HOME is empty -- filepath.Join would
28+
// produce a relative ".local/bin/<cli>" that could match an unintended
29+
// binary in the working directory.
30+
if userProfile != "" {
31+
locations = append(locations, filepath.Join(userProfile, ".local", "bin", cli))
32+
}
33+
locations = append(locations,
2734
filepath.Join("/", "snap", "bin", cli),
2835
)
2936
}

0 commit comments

Comments
 (0)