mirror of
https://github.com/ipfs/kubo.git
synced 2026-03-11 19:27:51 +08:00
Merge pull request #8318 from ipfs/fix/path-panic
fix: avoid out of bounds error when rendering short hashes
This commit is contained in:
commit
7c76118b0b
@ -412,11 +412,12 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request
|
||||
size = humanize.Bytes(uint64(s))
|
||||
}
|
||||
|
||||
hash := ""
|
||||
if r, err := i.api.ResolvePath(r.Context(), ipath.Join(resolvedPath, dirit.Name())); err == nil {
|
||||
// Path may not be resolved. Continue anyways.
|
||||
hash = r.Cid().String()
|
||||
resolved, err := i.api.ResolvePath(r.Context(), ipath.Join(resolvedPath, dirit.Name()))
|
||||
if err != nil {
|
||||
internalWebError(w, err)
|
||||
return
|
||||
}
|
||||
hash := resolved.Cid().String()
|
||||
|
||||
// See comment above where originalUrlPath is declared.
|
||||
di := directoryItem{
|
||||
|
||||
@ -75,6 +75,9 @@ func breadcrumbs(urlPath string, dnslinkOrigin bool) []breadcrumb {
|
||||
}
|
||||
|
||||
func shortHash(hash string) string {
|
||||
if len(hash) <= 8 {
|
||||
return hash
|
||||
}
|
||||
return (hash[0:4] + "\u2026" + hash[len(hash)-4:])
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user