diff --git a/internal/chezmoi/path_unix.go b/internal/chezmoi/path_unix.go index bcee9f6e03b..bc9db148674 100644 --- a/internal/chezmoi/path_unix.go +++ b/internal/chezmoi/path_unix.go @@ -12,6 +12,7 @@ var devNullAbsPath = NewAbsPath("/dev/null") // NewAbsPathFromExtPath returns a new AbsPath by converting extPath to use // slashes, performing tilde expansion, and making the path absolute. func NewAbsPathFromExtPath(extPath string, homeDirAbsPath AbsPath) (AbsPath, error) { + extPath = filepath.Clean(extPath) switch { case extPath == "~": return homeDirAbsPath, nil diff --git a/internal/chezmoi/path_windows.go b/internal/chezmoi/path_windows.go index 3a9f2dbff3f..fb6b7eb582e 100644 --- a/internal/chezmoi/path_windows.go +++ b/internal/chezmoi/path_windows.go @@ -11,6 +11,7 @@ var devNullAbsPath = NewAbsPath("NUL:") // slashes, performing tilde expansion, making the path absolute, and converting // the volume name to uppercase. func NewAbsPathFromExtPath(extPath string, homeDirAbsPath AbsPath) (AbsPath, error) { + extPath = filepath.Clean(extPath) switch { case extPath == "~": return homeDirAbsPath, nil diff --git a/internal/cmd/testdata/scripts/issue3374.txtar b/internal/cmd/testdata/scripts/issue3374.txtar new file mode 100644 index 00000000000..8bf342d59c3 --- /dev/null +++ b/internal/cmd/testdata/scripts/issue3374.txtar @@ -0,0 +1,8 @@ +# test that chezmoi copes with extra slashes in path arguments +exec chezmoi cat $HOME//.file +cmp stdout golden/.file + +-- golden/.file -- +# contents of .file +-- home/user/.local/share/chezmoi/dot_file -- +# contents of .file