1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-04 18:19:54 +00:00

Fix a bug with out-of-bounds indexing

This commit is contained in:
bouncepaw 2021-04-07 21:49:00 +05:00
parent 690b9ca339
commit d65e976a43

View File

@ -13,9 +13,9 @@ import (
func findSiblingsAndDescendants(hyphaName string) ([]*sibling, map[string]bool) {
var (
siblings = make([]*sibling, 0)
siblings = []*sibling{&sibling{hyphaName, 0, 0}}
siblingCheck = func(h *hyphae.Hypha) hyphae.CheckResult {
if path.Dir(hyphaName) == path.Dir(h.Name) {
if path.Dir(hyphaName) == path.Dir(h.Name) && h.Name != hyphaName {
siblings = append(siblings, &sibling{h.Name, 0, 0})
}
return hyphae.CheckContinue
@ -92,10 +92,10 @@ func Tree(hyphaName string) (siblingsHTML, childrenHTML, prev, next string) {
siblingsHTML += s.asHTML(hyphaName)
}
}
if I != 0 {
if I != 0 && len(siblings) > 1 {
prev = siblings[I-1].name
}
if I != len(siblings)-1 {
if I != len(siblings)-1 && len(siblings) > 1 {
next = siblings[I+1].name
}
return fmt.Sprintf(`<ul class="navitree">%s</ul>`, siblingsHTML), subhyphaeMatrix(children), prev, next