Skip to content

Commit 4bb1cb6

Browse files
committed
fix: return the shortest, completely resolved path in the resolve command
fixes #5703 License: MIT Signed-off-by: Steven Allen <steven@stebalien.com>
1 parent ef94a43 commit 4bb1cb6

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
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: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ test_expect_success "resolve: prepare files" '
1818
'
1919

2020
test_expect_success "resolve: prepare dag" '
21-
dag_hash=$(ipfs dag put <<<"{\"a\": {\"b\": {\"c\": \"asdfasdfasdf\"}}}")
21+
dag_hash=$(ipfs dag put <<<"{\"i\": {\"j\": {\"k\": \"asdfasdfasdf\"}}}")
2222
'
2323

2424
test_resolve_setup_name() {
@@ -65,6 +65,9 @@ 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/i/j/k" "/ipld/$dag_hash/i/j/k"
69+
test_resolve "/ipld/$dag_hash/i/j" "/ipld/$dag_hash/i/j"
70+
test_resolve "/ipld/$dag_hash/i" "/ipld/$dag_hash/i"
6871

6972
test_resolve_setup_name "/ipfs/$a_hash"
7073
test_resolve "/ipns/$id_hash" "/ipfs/$a_hash"
@@ -124,10 +127,9 @@ test_resolve_cmd_fail() {
124127
test_resolve "/ipfs/$a_hash/b/c" "/ipfs/$c_hash"
125128
test_resolve "/ipfs/$b_hash/c" "/ipfs/$c_hash"
126129
test_resolve "/ipld/$dag_hash" "/ipld/$dag_hash"
127-
128-
test_resolve_fail "/ipld/$dag_hash/a/b/c" "/ipld/$dag_hash/a/b/c"
129-
test_resolve_fail "/ipld/$dag_hash/a/b" "/ipld/$dag_hash/a/b"
130-
test_resolve_fail "/ipld/$dag_hash/a" "/ipld/$dag_hash/a"
130+
test_resolve "/ipld/$dag_hash/i/j/k" "/ipld/$dag_hash/i/j/k"
131+
test_resolve "/ipld/$dag_hash/i/j" "/ipld/$dag_hash/i/j"
132+
test_resolve "/ipld/$dag_hash/i" "/ipld/$dag_hash/i"
131133

132134
test_resolve_setup_name_fail "/ipfs/$a_hash"
133135
test_resolve_fail "/ipns/$id_hash" "/ipfs/$a_hash"

0 commit comments

Comments
 (0)