From ce707438296d77788392c0a4f9d32eee0a7f1ab8 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Tue, 14 Jul 2015 12:01:01 -0700 Subject: [PATCH 1/4] fix parsing for paths of format /path License: MIT Signed-off-by: Jeromy --- path/path.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/path/path.go b/path/path.go index 6fe75adbe..e865ba287 100644 --- a/path/path.go +++ b/path/path.go @@ -56,10 +56,9 @@ func ParsePath(txt string) (Path, error) { return kp, nil } } - if len(parts) < 3 { - return "", ErrBadPath - } + // if the path doesnt being with a '/' + // we expect this to start with a hash, and be an 'ipfs' path if parts[0] != "" { if _, err := ParseKeyToPath(parts[0]); err != nil { return "", ErrBadPath @@ -68,6 +67,10 @@ func ParsePath(txt string) (Path, error) { return Path("/ipfs/" + txt), nil } + if len(parts) < 3 { + return "", ErrBadPath + } + if parts[1] == "ipfs" { if _, err := ParseKeyToPath(parts[2]); err != nil { return "", err From 839759ae4fa8a0597259f3fd1b09271aba0132b1 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Tue, 14 Jul 2015 12:16:10 -0700 Subject: [PATCH 2/4] add tests for path parsing License: MIT Signed-off-by: Jeromy --- path/path_test.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 path/path_test.go diff --git a/path/path_test.go b/path/path_test.go new file mode 100644 index 000000000..f800e19e7 --- /dev/null +++ b/path/path_test.go @@ -0,0 +1,30 @@ +package path + +import ( + "testing" +) + +func TestPathParsing(t *testing.T) { + cases := map[string]bool{ + "/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n": true, + "/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n/a": true, + "/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n/a/b/c/d/e/f": true, + "/ipns/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n/a/b/c/d/e/f": true, + "/ipns/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n": true, + "QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n/a/b/c/d/e/f": true, + "QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n": true, + "/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n": false, + "/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n/a": false, + "/ipfs/": false, + "ipfs/": false, + "ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n": false, + } + + for p, expected := range cases { + _, err := ParsePath(p) + valid := (err == nil) + if valid != expected { + t.Fatalf("expected %s to have valid == %s", p, expected) + } + } +} From 4cce6f8adf44cb73c56b3dce7c408670a70e34dd Mon Sep 17 00:00:00 2001 From: Jeromy Date: Tue, 14 Jul 2015 12:28:38 -0700 Subject: [PATCH 3/4] add sharness test to check object stat with no leading /ipfs/ License: MIT Signed-off-by: Jeromy --- test/sharness/t0051-object.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/sharness/t0051-object.sh b/test/sharness/t0051-object.sh index c41dd621f..6460f15d1 100755 --- a/test/sharness/t0051-object.sh +++ b/test/sharness/t0051-object.sh @@ -114,6 +114,19 @@ test_object_cmd() { test_cmp hwfile hwfile_out ' + test_expect_success "ipfs object stat path succeeds" ' + ipfs object stat $(cat multi_patch)/a/b/c > obj_stat_out + ' + + test_expect_success "ipfs object stat output looks good" ' + echo NumLinks: 0 > obj_stat_exp && + echo BlockSize: 20 >> obj_stat_exp && + echo LinksSize: 2 >> obj_stat_exp && + echo DataSize: 18 >> obj_stat_exp && + echo CumulativeSize: 20 >> obj_stat_exp && + test_cmp obj_stat_out obj_stat_exp + ' + test_expect_success "should have created dir within a dir" ' ipfs ls $OUTPUT > patched_output ' From 5711eb8cd96f69add0e5dc11bdc44b1613f4125d Mon Sep 17 00:00:00 2001 From: Jeromy Date: Tue, 14 Jul 2015 13:28:22 -0700 Subject: [PATCH 4/4] better test of failure case License: MIT Signed-off-by: Jeromy --- test/sharness/t0051-object.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/test/sharness/t0051-object.sh b/test/sharness/t0051-object.sh index 6460f15d1..7ee088a5a 100755 --- a/test/sharness/t0051-object.sh +++ b/test/sharness/t0051-object.sh @@ -115,15 +115,16 @@ test_object_cmd() { ' test_expect_success "ipfs object stat path succeeds" ' - ipfs object stat $(cat multi_patch)/a/b/c > obj_stat_out + ipfs object stat $(cat multi_patch)/a > obj_stat_out ' test_expect_success "ipfs object stat output looks good" ' - echo NumLinks: 0 > obj_stat_exp && - echo BlockSize: 20 >> obj_stat_exp && - echo LinksSize: 2 >> obj_stat_exp && - echo DataSize: 18 >> obj_stat_exp && - echo CumulativeSize: 20 >> obj_stat_exp && + echo NumLinks: 1 > obj_stat_exp && + echo BlockSize: 47 >> obj_stat_exp && + echo LinksSize: 45 >> obj_stat_exp && + echo DataSize: 2 >> obj_stat_exp && + echo CumulativeSize: 114 >> obj_stat_exp && + test_cmp obj_stat_out obj_stat_exp '