Refactor:move clean method to suitable place

k3s-v1.15.3
yanghaichao12 2019-05-07 14:23:30 -04:00
parent a1588cfe34
commit e21ce73fba
2 changed files with 6 additions and 6 deletions

View File

@ -413,12 +413,6 @@ func recursiveTar(srcBase, srcFile, destBase, destFile string, tw *tar.Writer) e
return nil
}
// clean prevents path traversals by stripping them out.
// This is adapted from https://golang.org/src/net/http/fs.go#L74
func clean(fileName string) string {
return path.Clean(string(os.PathSeparator) + fileName)
}
func (o *CopyOptions) untarAll(reader io.Reader, destDir, prefix string) error {
// TODO: use compression here?
tarReader := tar.NewReader(reader)

View File

@ -551,6 +551,12 @@ func TestBadTar(t *testing.T) {
}
}
// clean prevents path traversals by stripping them out.
// This is adapted from https://golang.org/src/net/http/fs.go#L74
func clean(fileName string) string {
return path.Clean(string(os.PathSeparator) + fileName)
}
func TestClean(t *testing.T) {
tests := []struct {
input string