Skip to content

Commit

Permalink
fix: Handle extra slashes in path arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed Nov 30, 2023
1 parent 0b38793 commit c68ddac
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/chezmoi/path_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions internal/chezmoi/path_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions internal/cmd/testdata/scripts/issue3374.txtar
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c68ddac

Please sign in to comment.