From 613c518115dacb81d3e02a7505aa0dbfeaa0cc9c Mon Sep 17 00:00:00 2001 From: Lander Visterin Date: Mon, 3 Jul 2023 14:08:41 +0200 Subject: [PATCH] fix: normalizePath tilde expansion on Windows normalizePath sometimes gets backslash paths as input. In such case it will not be able to act on the ~/ prefix, since it will be \~ instead. FromSlash will provide the correct variant. --- internal/core/util.go | 2 +- internal/core/util_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/core/util.go b/internal/core/util.go index 1ef4ce61..e497a8f2 100755 --- a/internal/core/util.go +++ b/internal/core/util.go @@ -233,7 +233,7 @@ func normalizePath(path string) string { } if path == "~" { return homedir - } else if strings.HasPrefix(path, "~/") { + } else if strings.HasPrefix(path, filepath.FromSlash("~/")) { path = filepath.Join(homedir, path[2:]) } return path diff --git a/internal/core/util_test.go b/internal/core/util_test.go index ca1169f5..1da71e9e 100755 --- a/internal/core/util_test.go +++ b/internal/core/util_test.go @@ -55,7 +55,7 @@ func TestNormalizePath(t *testing.T) { t.Log("os.UserHomeDir failed, will not proceed with tests") return } - stylesPathInput := "~/.vale" + stylesPathInput := filepath.FromSlash("~/.vale") expectedOutput := filepath.Join(homedir, ".vale") result := normalizePath(stylesPathInput) if result != expectedOutput {