diff --git a/path.go b/path.go index df05000..f49dde1 100644 --- a/path.go +++ b/path.go @@ -10,7 +10,7 @@ import ( ) // A Path represents an ipfs content path: -// * //path/to/file +// * /path/to/file // * /ipfs/ // * /ipns//path/to/folder // * etc @@ -104,7 +104,7 @@ func ParsePath(txt string) (Path, error) { } if len(parts) < 3 { - return "", &pathError{error: fmt.Errorf("path does not begin with '/'"), path: txt} + return "", &pathError{error: fmt.Errorf("invalid ipfs path"), path: txt} } //TODO: make this smarter diff --git a/path_test.go b/path_test.go index 42cacdd..2b26a56 100644 --- a/path_test.go +++ b/path_test.go @@ -51,6 +51,19 @@ func TestNoComponents(t *testing.T) { } } +func TestInvalidPaths(t *testing.T) { + for _, s := range []string{ + "/ipfs", + "/testfs", + "/", + } { + _, err := ParsePath(s) + if err == nil || !strings.Contains(err.Error(), "invalid ipfs path") || !strings.Contains(err.Error(), s) { + t.Error("wrong error") + } + } +} + func TestIsJustAKey(t *testing.T) { cases := map[string]bool{ "QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n": true,