Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
10c36282
Commit
10c36282
authored
9 years ago
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1282 from travisperson/bug/panic-on-empty-path
Bug/panic on empty path
parents
988b158d
2c71c548
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
1 deletion
+36
-1
core/pathresolver.go
core/pathresolver.go
+5
-0
core/pathresolver_test.go
core/pathresolver_test.go
+25
-0
path/resolver.go
path/resolver.go
+6
-1
No files found.
core/pathresolver.go
View file @
10c36282
...
...
@@ -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
{
...
...
This diff is collapsed.
Click to expand it.
core/pathresolver_test.go
0 → 100644
View file @
10c36282
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
)
}
}
This diff is collapsed.
Click to expand it.
path/resolver.go
View file @
10c36282
...
...
@@ -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 c
omponent
"
)
return
nil
,
nil
,
ErrNoC
omponent
s
}
// first element in the path is a b58 hash (for now)
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment