unixfs: clean path in DagArchive
Fixes #4720. License: MIT Signed-off-by: Lucas Molas <schomatis@gmail.com>
Lucas Molas committed
Feb 28, 2018 at 10:29 UTC
f710b31ff4a289fa8efeb3c4c23c4cf0c55a7d4a
2 files changed
+10
-1
test/sharness/t0090-get.sh
+8
@@ -104,6 +104,14 @@ test_get_cmd() {
104
rm -r "$HASH2"
105
'
106
107
+ # Test issue #4720: problems when path contains a trailing slash.
108
+ test_expect_success "ipfs get with slash (directory)" '
109
+ ipfs get "$HASH2/" &&
110
+ test_cmp dir/a "$HASH2"/a &&
111
+ test_cmp dir/b/c "$HASH2"/b/c &&
112
+ rm -r "$HASH2"
113
+ '
114
+
115
test_expect_success "ipfs get -a -C succeeds (directory)" '
116
ipfs get "$HASH2" -a -C >actual
117
'
unixfs/archive/archive.go
+2
-1
@@ -33,7 +33,8 @@ func (i *identityWriteCloser) Close() error {
33
// DagArchive is equivalent to `ipfs getdag $hash | maybe_tar | maybe_gzip`
34
func DagArchive(ctx context.Context, nd ipld.Node, name string, dag ipld.DAGService, archive bool, compression int) (io.Reader, error) {
35
36
- _, filename := path.Split(name)
36
+ cleaned := path.Clean(name)
37
+ _, filename := path.Split(cleaned)
38
39
// need to connect a writer to a reader
40
piper, pipew := io.Pipe()