Skip to content

Commit

Permalink
fix: return the shortest, completely resolved path in the resolve com…
Browse files Browse the repository at this point in the history
…mand

fixes #5703

License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
  • Loading branch information
Stebalien committed Feb 19, 2019
1 parent ef94a43 commit 082dcda
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 4 additions & 5 deletions core/commands/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,12 @@ Resolve the value of an IPFS DAG path:
return err
}

if rp.Remainder() != "" {
// TODO: js expects this error. Instead of fixing this
// error, we should fix #5703.
return fmt.Errorf("found non-link at given path")
encoded := "/" + rp.Namespace() + "/" + enc.Encode(rp.Cid())
if remainder := rp.Remainder(); remainder != "" {
encoded += "/" + remainder
}

return cmds.EmitOnce(res, &ncmd.ResolvedPath{Path: path.Path("/" + rp.Namespace() + "/" + enc.Encode(rp.Cid()))})
return cmds.EmitOnce(res, &ncmd.ResolvedPath{Path: path.Path(encoded)})
},
Encoders: cmds.EncoderMap{
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, rp *ncmd.ResolvedPath) error {
Expand Down
2 changes: 2 additions & 0 deletions test/sharness/t0160-resolve.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ test_resolve_cmd() {
test_resolve "/ipfs/$a_hash/b" "/ipfs/$b_hash"
test_resolve "/ipfs/$a_hash/b/c" "/ipfs/$c_hash"
test_resolve "/ipfs/$b_hash/c" "/ipfs/$c_hash"
test_resolve "/ipld/$dag_hash/a/b/c" "/ipld/$dag_hash/a/b/c"
test_resolve "/ipld/$dag_hash/a/b" "/ipld/$dag_hash/a/b"

test_resolve_setup_name "/ipfs/$a_hash"
test_resolve "/ipns/$id_hash" "/ipfs/$a_hash"
Expand Down

0 comments on commit 082dcda

Please sign in to comment.