From 5e4e8349c90f7dfcbb97fc550aa721545d4e5ba6 Mon Sep 17 00:00:00 2001 From: Shu Shen Date: Wed, 9 Feb 2022 22:07:06 -0800 Subject: [PATCH 1/2] chore: improve error message for invalid ipfs paths --- path.go | 2 +- path_test.go | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/path.go b/path.go index df05000..bc9065a 100644 --- a/path.go +++ b/path.go @@ -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, From 9500a344406b9c33831bce44770c78394e0c5824 Mon Sep 17 00:00:00 2001 From: Shu Shen Date: Wed, 9 Feb 2022 22:11:54 -0800 Subject: [PATCH 2/2] chore: update doc to match implementation for CID only paths --- path.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/path.go b/path.go index bc9065a..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