Skip to content

Commit 9fae163

Browse files
committed
update
1 parent 7a79ddf commit 9fae163

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

archive.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,18 @@ func Zip(srcDirPath string, destFilePath string, args ...*regexp.Regexp) (n int6
7878
return
7979
}
8080

81-
func IllegalFilePath(path string) bool {
81+
func IllegalFilePath(fpath string) bool {
82+
if fpath == `..` {
83+
return true
84+
}
85+
if strings.HasSuffix(fpath, `..`) {
86+
i := len(fpath) - 3
87+
if fpath[i] == '/' || fpath[i] == '\\' {
88+
return true
89+
}
90+
}
8291
var dots int
83-
for _, c := range path {
92+
for _, c := range fpath {
8493
switch c {
8594
case '.':
8695
dots++

archive_test.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,29 @@ import (
88
"github.com/stretchr/testify/assert"
99
)
1010

11-
func TestZip(t *testing.T) {
12-
MkdirAll(`testdata`, os.ModePerm)
13-
n, err := Zip(`./encoding`, `testdata/test.zip`)
14-
assert.NoError(t, err)
15-
assert.NotEqual(t, n, 0)
16-
17-
err = Unzip(`testdata/test.zip`, `testdata/unarchive`)
18-
assert.NoError(t, err)
19-
11+
func TestIllegalFilePath(t *testing.T) {
2012
assert.Equal(t, `/a/b/c`, filepath.Dir(`/a/b/c/..a.txt`))
2113
assert.Equal(t, `/a/b`, filepath.Dir(`/a/b/c/../a.txt`))
2214
assert.Equal(t, `/abc/a/b/a.txt`, filepath.Join(`/abc`, `/a/b/c/../a.txt`))
2315
assert.Equal(t, `/abc/a\b\c\..\a.txt`, filepath.Join(`/abc`, `/a\b\c\..\a.txt`))
2416
assert.Equal(t, `/abc/a/b/c/..a.txt`, filepath.Join(`/abc`, `/a/b/c/..a.txt`))
17+
assert.Equal(t, `/a/b`, filepath.Join(`/a/b/c`, `..`))
18+
assert.Equal(t, `/a/b`, filepath.Join(`/a/b/c/..`))
2519
assert.True(t, IllegalFilePath(`a/b/c/../a.txt`))
2620
assert.True(t, IllegalFilePath(`a/b/c/..\a.txt`))
2721
assert.False(t, IllegalFilePath(`a/b/c/..a.txt`))
22+
assert.True(t, IllegalFilePath(`..`))
23+
assert.True(t, IllegalFilePath(`/..`))
24+
}
25+
26+
func TestZip(t *testing.T) {
27+
MkdirAll(`testdata`, os.ModePerm)
28+
n, err := Zip(`./encoding`, `testdata/test.zip`)
29+
assert.NoError(t, err)
30+
assert.NotEqual(t, n, 0)
31+
32+
err = Unzip(`testdata/test.zip`, `testdata/unarchive`)
33+
assert.NoError(t, err)
2834
}
2935

3036
func TestTarGz(t *testing.T) {

0 commit comments

Comments
 (0)