@@ -96,7 +96,7 @@ func ParsePath(txt string) (Path, error) {
96
96
// if the path doesnt begin with a '/'
97
97
// we expect this to start with a hash, and be an 'ipfs' path
98
98
if parts [0 ] != "" {
99
- if _ , err := cid . Decode (parts [0 ]); err != nil {
99
+ if _ , err := decodeCid (parts [0 ]); err != nil {
100
100
return "" , & pathError {error : err , path : txt }
101
101
}
102
102
// The case when the path starts with hash without a protocol prefix
@@ -114,7 +114,7 @@ func ParsePath(txt string) (Path, error) {
114
114
return "" , & pathError {error : fmt .Errorf ("not enough path components" ), path : txt }
115
115
}
116
116
// Validate Cid.
117
- _ , err := cid . Decode (parts [2 ])
117
+ _ , err := decodeCid (parts [2 ])
118
118
if err != nil {
119
119
return "" , & pathError {error : fmt .Errorf ("invalid CID: %s" , err ), path : txt }
120
120
}
@@ -135,7 +135,7 @@ func ParseCidToPath(txt string) (Path, error) {
135
135
return "" , & pathError {error : fmt .Errorf ("empty" ), path : txt }
136
136
}
137
137
138
- c , err := cid . Decode (txt )
138
+ c , err := decodeCid (txt )
139
139
if err != nil {
140
140
return "" , & pathError {error : err , path : txt }
141
141
}
@@ -172,11 +172,19 @@ func SplitAbsPath(fpath Path) (cid.Cid, []string, error) {
172
172
return cid.Cid {}, nil , & pathError {error : fmt .Errorf ("empty" ), path : string (fpath )}
173
173
}
174
174
175
- c , err := cid . Decode (parts [0 ])
175
+ c , err := decodeCid (parts [0 ])
176
176
// first element in the path is a cid
177
177
if err != nil {
178
178
return cid.Cid {}, nil , & pathError {error : fmt .Errorf ("invalid CID: %s" , err ), path : string (fpath )}
179
179
}
180
180
181
181
return c , parts [1 :], nil
182
182
}
183
+
184
+ func decodeCid (cstr string ) (cid.Cid , error ) {
185
+ c , err := cid .Decode (cstr )
186
+ if err != nil && len (cstr ) == 46 && cstr [:2 ] == "qm" { // https://github.com/ipfs/go-ipfs/issues/7792
187
+ return cid.Cid {}, fmt .Errorf ("%v (possible lowercased CIDv0; consider converting to a case-agnostic CIDv1, such as base32)" , err )
188
+ }
189
+ return c , err
190
+ }
0 commit comments