@@ -96,7 +96,7 @@ func ParsePath(txt string) (Path, error) {
9696 // if the path doesnt begin with a '/'
9797 // we expect this to start with a hash, and be an 'ipfs' path
9898 if parts [0 ] != "" {
99- if _ , err := cid . Decode (parts [0 ]); err != nil {
99+ if _ , err := decodeCid (parts [0 ]); err != nil {
100100 return "" , & pathError {error : err , path : txt }
101101 }
102102 // The case when the path starts with hash without a protocol prefix
@@ -114,7 +114,7 @@ func ParsePath(txt string) (Path, error) {
114114 return "" , & pathError {error : fmt .Errorf ("not enough path components" ), path : txt }
115115 }
116116 // Validate Cid.
117- _ , err := cid . Decode (parts [2 ])
117+ _ , err := decodeCid (parts [2 ])
118118 if err != nil {
119119 return "" , & pathError {error : fmt .Errorf ("invalid CID: %s" , err ), path : txt }
120120 }
@@ -135,7 +135,7 @@ func ParseCidToPath(txt string) (Path, error) {
135135 return "" , & pathError {error : fmt .Errorf ("empty" ), path : txt }
136136 }
137137
138- c , err := cid . Decode (txt )
138+ c , err := decodeCid (txt )
139139 if err != nil {
140140 return "" , & pathError {error : err , path : txt }
141141 }
@@ -172,11 +172,19 @@ func SplitAbsPath(fpath Path) (cid.Cid, []string, error) {
172172 return cid.Cid {}, nil , & pathError {error : fmt .Errorf ("empty" ), path : string (fpath )}
173173 }
174174
175- c , err := cid . Decode (parts [0 ])
175+ c , err := decodeCid (parts [0 ])
176176 // first element in the path is a cid
177177 if err != nil {
178178 return cid.Cid {}, nil , & pathError {error : fmt .Errorf ("invalid CID: %s" , err ), path : string (fpath )}
179179 }
180180
181181 return c , parts [1 :], nil
182182}
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