Skip to content

Commit

Permalink
Support whitespace and non-ASCI characters in path.
Browse files Browse the repository at this point in the history
  • Loading branch information
wsobolewski committed Feb 27, 2024
1 parent 94f952a commit bab56da
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/nvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ type Environment struct {

var home = filepath.Clean(os.Getenv("NVM_HOME") + "\\settings.txt")
var symlink = filepath.Clean(os.Getenv("NVM_SYMLINK"))
var root = filepath.Clean(os.Getenv("NVM_HOME"))

var env = &Environment{
settings: home,
root: "",
root: root,
symlink: symlink,
arch: os.Getenv("PROCESSOR_ARCHITECTURE"),
node_mirror: "",
Expand Down Expand Up @@ -1421,6 +1422,7 @@ func saveSettings() {
content := "root: " + strings.Trim(encode(env.root), " \n\r") + "\r\narch: " + strings.Trim(encode(env.arch), " \n\r") + "\r\nproxy: " + strings.Trim(encode(env.proxy), " \n\r") + "\r\noriginalpath: " + strings.Trim(encode(env.originalpath), " \n\r") + "\r\noriginalversion: " + strings.Trim(encode(env.originalversion), " \n\r")
content = content + "\r\nnode_mirror: " + strings.Trim(encode(env.node_mirror), " \n\r") + "\r\nnpm_mirror: " + strings.Trim(encode(env.npm_mirror), " \n\r")
ioutil.WriteFile(env.settings, []byte(content), 0644)
os.Setenv("NVM_HOME", strings.Trim(encode(env.root), " \n\r"))
}

func getProcessPermissions() (admin bool, elevated bool, err error) {
Expand Down Expand Up @@ -1479,8 +1481,8 @@ func setup() {
m[res[0]] = strings.TrimSpace(strings.Join(res[1:], ":"))
}

if val, ok := m["root"]; ok {
env.root = filepath.Clean(val)
if _, ok := m["root"]; ok {
env.root = filepath.Clean(os.Getenv("NVM_HOME"))
}
if val, ok := m["originalpath"]; ok {
env.originalpath = filepath.Clean(val)
Expand Down

0 comments on commit bab56da

Please # to comment.