Skip to content

Commit 4fe3a72

Browse files
committed
fix: return the shortest, completely resolved path in the resolve command
fixes #5703 License: MIT Signed-off-by: Steven Allen <[email protected]>
1 parent 77cd41a commit 4fe3a72

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

core/commands/resolve.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,12 @@ Resolve the value of an IPFS DAG path:
140140
return err
141141
}
142142

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

149-
return cmds.EmitOnce(res, &ncmd.ResolvedPath{Path: path.Path("/" + rp.Namespace() + "/" + enc.Encode(rp.Cid()))})
148+
return cmds.EmitOnce(res, &ncmd.ResolvedPath{Path: path.Path(encoded)})
150149
},
151150
Encoders: cmds.EncoderMap{
152151
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, rp *ncmd.ResolvedPath) error {

test/sharness/t0160-resolve.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ test_resolve_cmd() {
6565
test_resolve "/ipfs/$a_hash/b" "/ipfs/$b_hash"
6666
test_resolve "/ipfs/$a_hash/b/c" "/ipfs/$c_hash"
6767
test_resolve "/ipfs/$b_hash/c" "/ipfs/$c_hash"
68+
test_resolve "/ipld/$dag_hash/a/b/c" "/ipld/$dag_hash/a/b/c"
69+
test_resolve "/ipld/$dag_hash/a/b" "/ipld/$dag_hash/a/b"
6870

6971
test_resolve_setup_name "/ipfs/$a_hash"
7072
test_resolve "/ipns/$id_hash" "/ipfs/$a_hash"

0 commit comments

Comments
 (0)