@cryptotaxi247 / kubo / commits / f8adc3ebd

fix(commands/cid): always use base58 for CIDv0 unless otherwise specified

Steven Allen committed Jan 7, 2020 at 11:17 UTC f8adc3ebdd12ac7125dc268fd1d48694c49b705d
2 files changed +17 -4
core/commands/cid.go
+11 -4
@@ -169,10 +169,7 @@ func emitCids(req *cmds.Request, resp cmds.ResponseEmitter, opts cidFormatOpts)
169 emitErr = resp.Emit(res)
170 continue
171 }
172 - base := opts.newBase
173 - if base == -1 {
174 - base, _ = cid.ExtractEncoding(cidStr)
175 - }
172 +
173 if opts.verConv != nil {
174 c, err = opts.verConv(c)
175 if err != nil {
@@ -181,6 +178,16 @@ func emitCids(req *cmds.Request, resp cmds.ResponseEmitter, opts cidFormatOpts)
178 continue
179 }
180 }
181 +
182 + base := opts.newBase
183 + if base == -1 {
184 + if c.Version() == 0 {
185 + base = mbase.Base58BTC
186 + } else {
187 + base, _ = cid.ExtractEncoding(cidStr)
188 + }
189 + }
190 +
191 str, err := cidutil.Format(opts.fmtStr, base, c)
192 if _, ok := err.(cidutil.FormatStringError); ok {
193 // no point in continuing if there is a problem with the format string
test/sharness/t0290-cid.sh
+6
@@ -26,6 +26,12 @@ test_expect_success "cid format -v 1 -b base58btc" '
26 test_cmp expected actual2
27 '
28
29 +test_expect_success "cid format -v 0" '
30 + echo $CIDv0 > expected &&
31 + ipfs cid format -v 0 $CIDb32 > actual &&
32 + test_cmp expected actual
33 +'
34 +
35 cat <<EOF > various_cids
36 QmZZRTyhDpL5Jgift1cHbAhexeE1m2Hw8x8g7rTcPahDvo
37 QmPhk6cJkRcFfZCdYam4c9MKYjFG9V29LswUnbrFNhtk2S