Skip to content

Commit

Permalink
fix: normalizePath tilde expansion on Windows (#656)
Browse files Browse the repository at this point in the history
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.

Co-authored-by: Lander Visterin <[email protected]>
  • Loading branch information
lanvstn and lvisterin authored Jul 4, 2023
1 parent 545983e commit 27fe2f6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion internal/core/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/core/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 27fe2f6

Please sign in to comment.