From c39eae924ef98d88fe4867fb0a8866c698bfd2dd Mon Sep 17 00:00:00 2001 From: Corey Butler <770982+coreybutler@users.noreply.github.com> Date: Sun, 25 Oct 2026 10:03:23 -0500 Subject: [PATCH] fix(config): reject blank root before NVM4313 Whitespace-only root is missing input, not an unsafe folder. processRoot must fail with the empty-path message before the install-root deny list so nvm config set matches Validate. Signed-off-by: Corey Butler <770982+coreybutler@users.noreply.github.com> --- config/config.go | 2 +- config/root.go | 4 ++++ config/root_test.go | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 config/root_test.go diff --git a/config/config.go b/config/config.go index 59ff0d0..57c48df 100644 --- a/config/config.go +++ b/config/config.go @@ -9,7 +9,7 @@ func Prepare(key, value *string) (skip bool, deferredFn func(), err error) { case "root": deferredFn, err = processRoot(value) - if err != nil && (strings.Contains(err.Error(), "blocked") || strings.Contains(err.Error(), "NVM4313")) { + if err != nil && (strings.Contains(err.Error(), "blocked") || strings.Contains(err.Error(), "NVM4313") || strings.Contains(err.Error(), "non-empty path")) { skip = true } diff --git a/config/root.go b/config/root.go index c20b535..02a4698 100644 --- a/config/root.go +++ b/config/root.go @@ -18,6 +18,10 @@ func processRoot(value *string) (deferredFn func(), err error) { } *value = strings.Trim(*value, `"`) // Remove potential quotes from input + if strings.TrimSpace(*value) == "" { + err = fmt.Errorf("root must be a non-empty path") + return + } sourceRoot := filepath.Clean(s.Root) targetRoot := filepath.Clean(settings.Expand(*value)) diff --git a/config/root_test.go b/config/root_test.go new file mode 100644 index 0000000..02b67e3 --- /dev/null +++ b/config/root_test.go @@ -0,0 +1,34 @@ +package config + +import ( + "os/exec" + "strings" + "testing" + + prefs "common/preferences" + "common/settings" +) + +func TestPrepareRootRejectsBlank(t *testing.T) { + prefs.ROOT = "HKCU/Software/NVMTest/config_empty_root" + prefs.ROOTS = []string{prefs.ROOT} + t.Cleanup(func() { + exec.Command("reg", "delete", `HKCU\Software\NVMTest\config_empty_root`, "/f").Run() + }) + settings.Load(true) + + for _, raw := range []string{"", " ", `""`, `" "`} { + key := "root" + value := raw + skip, _, err := Prepare(&key, &value) + if err == nil || !strings.Contains(err.Error(), "root must be a non-empty path") { + t.Fatalf("Prepare(root=%q) = skip=%v err=%v, want non-empty path", raw, skip, err) + } + if strings.Contains(err.Error(), "NVM4313") { + t.Fatalf("Prepare(root=%q) used NVM4313: %v", raw, err) + } + if !skip { + t.Fatalf("Prepare(root=%q) skip=false, want true", raw) + } + } +}