Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ipfs/kubo
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 988b158dc7dc
Choose a base ref
...
head repository: ipfs/kubo
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 10c362823e2a
Choose a head ref
  • 5 commits
  • 3 files changed
  • 2 contributors

Commits on May 22, 2015

  1. Daemon panics if no path is given

    If no path after `/ipfs/` or `/ipns/` is given, then the daemon will
    panic with a slice bounds out of range error. This checks to see if we
    have anything after `ipfs` or `ipns`.
    travisperson committed May 22, 2015
    Copy the full SHA
    42289d4 View commit details
  2. Replaced old logic to check for valid path

    Added the original logic to check for a invalid path and a simple test.
    travisperson committed May 22, 2015
    Copy the full SHA
    dcc4da0 View commit details
  3. Fixed tests to actually test for the error we are seeking

    Cleaned the tests, and actually test for the error.
    travisperson committed May 22, 2015
    Copy the full SHA
    d96246c View commit details
  4. Named error for no components

    Update the previous `invalid path` error to match the error returned
    from `SplitAbsPath`.
    travisperson committed May 22, 2015
    Copy the full SHA
    2c71c54 View commit details
  5. Merge pull request #1282 from travisperson/bug/panic-on-empty-path

    Bug/panic on empty path
    jbenet committed May 22, 2015
    Copy the full SHA
    10c3628 View commit details
Showing with 36 additions and 1 deletion.
  1. +5 −0 core/pathresolver.go
  2. +25 −0 core/pathresolver_test.go
  3. +6 −1 path/resolver.go
5 changes: 5 additions & 0 deletions core/pathresolver.go
Original file line number Diff line number Diff line change
@@ -29,6 +29,11 @@ func Resolve(ctx context.Context, n *IpfsNode, p path.Path) (*merkledag.Node, er
}

seg := p.Segments()

if len(seg) < 2 || seg[1] == "" { // just "/<protocol/>" without further segments
return nil, path.ErrNoComponents
}

extensions := seg[2:]
resolvable, err := path.FromSegments("/", seg[0], seg[1])
if err != nil {
25 changes: 25 additions & 0 deletions core/pathresolver_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package core

import (
"testing"

path "github.com/ipfs/go-ipfs/path"
)

func TestResolveNoComponents(t *testing.T) {
n, err := NewMockNode()
if n == nil || err != nil {
t.Fatal("Should have constructed a mock node", err)
}

_, err = Resolve(n.Context(), n, path.Path("/ipns/"))
if err != path.ErrNoComponents {
t.Fatal("Should error with no components (/ipns/).", err)
}

_, err = Resolve(n.Context(), n, path.Path("/ipfs/"))
if err != path.ErrNoComponents {
t.Fatal("Should error with no components (/ipfs/).", err)
}

}
7 changes: 6 additions & 1 deletion path/resolver.go
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ package path
import (
"fmt"
"time"
"errors"

mh "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
@@ -14,6 +15,10 @@ import (

var log = u.Logger("path")

// Paths after a protocol must contain at least one component
var ErrNoComponents = errors.New(
"path must contain at least one component")

// ErrNoLink is returned when a link is not found in a path
type ErrNoLink struct {
name string
@@ -43,7 +48,7 @@ func SplitAbsPath(fpath Path) (mh.Multihash, []string, error) {

// if nothing, bail.
if len(parts) == 0 {
return nil, nil, fmt.Errorf("ipfs path must contain at least one component")
return nil, nil, ErrNoComponents
}

// first element in the path is a b58 hash (for now)