Skip to content

Commit

Permalink
Use path.Join when setting zip.FileHeader.Name.
Browse files Browse the repository at this point in the history
zip.FileHeader.Name is documented to be a '/'-separated path,
rather than an os.PathSeparator-separated file system path:

	// Name is the name of the file.
	// It must be a relative path: it must not start with a drive
	// letter (e.g. C:) or leading slash, and only forward slashes
	// are allowed.

Source: https://godoc.org/archive/zip#FileHeader.Name

Therefore, it's correct to use path.Join rather than filepath.Join
when setting its value. Package path manipulates and produces
slash-separated paths, while package filepath manipulates and
produces os.PathSeparator-separated file system paths.

Updates #9.
  • Loading branch information
dmitshur authored Aug 29, 2016
1 parent 9abfedc commit c350559
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion zip.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func zipFile(w *zip.Writer, source string) error {
}

if baseDir != "" {
header.Name = filepath.Join(baseDir, strings.TrimPrefix(fpath, source))
header.Name = path.Join(baseDir, strings.TrimPrefix(fpath, source))
}

if info.IsDir() {
Expand Down

0 comments on commit c350559

Please sign in to comment.