fix: return the shortest, completely resolved path in the resolve command
fixes #5703 License: MIT Signed-off-by: Steven Allen <steven@stebalien.com>
Steven Allen committed
Oct 30, 2018 at 10:22 UTC
4bb1cb65e85f828a3f3e61c1b9ee3bde7aa202ad
2 files changed
+11
-10
core/commands/resolve.go
+4
-5
@@ -140,13 +140,12 @@ Resolve the value of an IPFS DAG path:
140
return err
141
}
142
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
146
}
147
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)})
149
},
150
Encoders: cmds.EncoderMap{
151
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, rp *ncmd.ResolvedPath) error {
test/sharness/t0160-resolve.sh
+7
-5
@@ -18,7 +18,7 @@ test_expect_success "resolve: prepare files" '
18
'
19
20
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\"}}}")
22
'
23
24
test_resolve_setup_name() {
@@ -65,6 +65,9 @@ test_resolve_cmd() {
65
test_resolve "/ipfs/$a_hash/b" "/ipfs/$b_hash"
66
test_resolve "/ipfs/$a_hash/b/c" "/ipfs/$c_hash"
67
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"
71
72
test_resolve_setup_name "/ipfs/$a_hash"
73
test_resolve "/ipns/$id_hash" "/ipfs/$a_hash"
@@ -124,10 +127,9 @@ test_resolve_cmd_fail() {
127
test_resolve "/ipfs/$a_hash/b/c" "/ipfs/$c_hash"
128
test_resolve "/ipfs/$b_hash/c" "/ipfs/$c_hash"
129
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"
133
134
test_resolve_setup_name_fail "/ipfs/$a_hash"
135
test_resolve_fail "/ipns/$id_hash" "/ipfs/$a_hash"