always trim './'
Signed-off-by: liangchenye <liangchenye@huawei.com>
This commit is contained in:
parent
d402ae818e
commit
354c4b3672
@ -58,7 +58,10 @@ func SelectivelyExtractArchive(r io.Reader, prefix string, toExtract []string, m
|
|||||||
|
|
||||||
// Get element filename
|
// Get element filename
|
||||||
filename := hdr.Name
|
filename := hdr.Name
|
||||||
|
filename = strings.TrimPrefix(filename, "./")
|
||||||
|
if prefix != "" {
|
||||||
filename = strings.TrimPrefix(filename, prefix)
|
filename = strings.TrimPrefix(filename, prefix)
|
||||||
|
}
|
||||||
|
|
||||||
// Determine if we should extract the element
|
// Determine if we should extract the element
|
||||||
toBeExtracted := false
|
toBeExtracted := false
|
||||||
|
@ -65,13 +65,13 @@ func TestTar(t *testing.T) {
|
|||||||
testArchivePath := path.Join(path.Dir(filepath)) + filename
|
testArchivePath := path.Join(path.Dir(filepath)) + filename
|
||||||
|
|
||||||
// Extract non compressed data
|
// Extract non compressed data
|
||||||
data, err = SelectivelyExtractArchive(bytes.NewReader([]byte("that string does not represent a tar or tar-gzip file")), "./", []string{}, 0)
|
data, err = SelectivelyExtractArchive(bytes.NewReader([]byte("that string does not represent a tar or tar-gzip file")), "", []string{}, 0)
|
||||||
assert.Error(t, err, "Extracting non compressed data should return an error")
|
assert.Error(t, err, "Extracting non compressed data should return an error")
|
||||||
|
|
||||||
// Extract an archive
|
// Extract an archive
|
||||||
f, _ := os.Open(testArchivePath)
|
f, _ := os.Open(testArchivePath)
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
data, err = SelectivelyExtractArchive(f, "./", []string{"test/"}, 0)
|
data, err = SelectivelyExtractArchive(f, "", []string{"test/"}, 0)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
if c, n := data["test/test.txt"]; !n {
|
if c, n := data["test/test.txt"]; !n {
|
||||||
@ -86,7 +86,7 @@ func TestTar(t *testing.T) {
|
|||||||
// File size limit
|
// File size limit
|
||||||
f, _ = os.Open(testArchivePath)
|
f, _ = os.Open(testArchivePath)
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
data, err = SelectivelyExtractArchive(f, "./", []string{"test"}, 50)
|
data, err = SelectivelyExtractArchive(f, "", []string{"test"}, 50)
|
||||||
assert.Equal(t, ErrExtractedFileTooBig, err)
|
assert.Equal(t, ErrExtractedFileTooBig, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,5 +42,5 @@ func (detector *TarDataDetector) Supported(path string, format string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (detector *TarDataDetector) Detect(layerReader io.ReadCloser, toExtract []string, maxFileSize int64) (map[string][]byte, error) {
|
func (detector *TarDataDetector) Detect(layerReader io.ReadCloser, toExtract []string, maxFileSize int64) (map[string][]byte, error) {
|
||||||
return utils.SelectivelyExtractArchive(layerReader, "./", toExtract, maxFileSize)
|
return utils.SelectivelyExtractArchive(layerReader, "", toExtract, maxFileSize)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user