From 1f1118448f3e129f19092cdfc713aa8e5baaef6e Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 30 Oct 2018 10:22:34 -0700 Subject: [PATCH] fix: return the shortest, completely resolved path in the resolve command fixes #5703 License: MIT Signed-off-by: Steven Allen --- core/commands/resolve.go | 9 ++++----- test/sharness/t0160-resolve.sh | 2 ++ 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/core/commands/resolve.go b/core/commands/resolve.go index 811fb25340d7..3ad7df54607f 100644 --- a/core/commands/resolve.go +++ b/core/commands/resolve.go @@ -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 != "" { + path += "/" + 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 { diff --git a/test/sharness/t0160-resolve.sh b/test/sharness/t0160-resolve.sh index 4a23d40a6504..85d87ff5785e 100755 --- a/test/sharness/t0160-resolve.sh +++ b/test/sharness/t0160-resolve.sh @@ -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"