Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Commit

Permalink
Merge pull request #18 from ipfs/fix/no-components-error
Browse files Browse the repository at this point in the history
fix: no components error
  • Loading branch information
Stebalien authored Jan 23, 2019
2 parents 1603d6d + ab96f18 commit af54515
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .gx/lastpubver
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.28: QmdCKmdARJPTzGFmhQAdmiNkH8x1NYJ5nR3oTuyMSheGe1
1.1.29: QmNqCEAGiUir2kPGTfYTADyKrdw9dHQ7MAaEAE5MGfXkcC
22 changes: 22 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
sudo: false


language: go
go:
- 1.11.x

before_install:
- make deps

script:
- bash <(curl -s https://raw.githubusercontent.com/ipfs/ci-helpers/master/travis-ci/run-standard-tests.sh)

after_success:
- bash <(curl -s https://codecov.io/bash)

cache:
directories:
- $GOPATH/src/gx

notifications:
email: false
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
gx:
go get github.com/whyrusleeping/gx
go get github.com/whyrusleeping/gx-go

deps: gx
gx --verbose install --global
gx-go rewrite

publish:
gx-go rewrite --undo

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@
"license": "",
"name": "go-path",
"releaseCmd": "git commit -a -m \"gx publish $VERSION\"",
"version": "1.1.28"
"version": "1.1.29"
}

7 changes: 6 additions & 1 deletion path.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,18 @@ func ParsePath(txt string) (Path, error) {
//TODO: make this smarter
switch parts[1] {
case "ipfs", "ipld":
if parts[2] == "" {
return "", ErrNoComponents
}
// Validate Cid.
_, err := cid.Decode(parts[2])
if err != nil {
return "", err
}
case "ipns":
// No validation.
if parts[2] == "" {
return "", ErrNoComponents
}
default:
return "", ErrBadPath
}
Expand Down
13 changes: 13 additions & 0 deletions path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ func TestPathParsing(t *testing.T) {
}
}

func TestNoComponents(t *testing.T) {
for _, s := range []string{
"/ipfs/",
"/ipns/",
"/ipld/",
} {
_, err := ParsePath(s)
if err != ErrNoComponents {
t.Errorf("expected ErrNoComponents, got %s", err)
}
}
}

func TestIsJustAKey(t *testing.T) {
cases := map[string]bool{
"QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n": true,
Expand Down

0 comments on commit af54515

Please sign in to comment.