Closed ShevaXu closed 7 years ago
Thanks for reporting it. I'll try to fix it as soon as possible.
I think the fix d325696 does not work because it is r.Pointer.NextSibling
might be nil, and calling .NextSibling
on it causing the nil pointer dereference crash/panic.
Maybe try this:
func (r Root) FindNextSibling() Node {
nextSibling := r.Pointer.NextSibling
if nextSibling == nil {
log.Fatal("No next sibling found")
}
// try to find next element-node?
if nextSibling.Type == html.ElementNode {
return Root{nextSibling}
} else {
// keep looking
}
}
Ah, I see it now. I'll make the fixes accordingly.
Fixed it in the above commit, and renamed them to FindNextElementSibling()
and FindPrevElementSibling()
I'll be implementing the actual FindNextSibling()
and FindPrevSibling()
in the upcoming commits.
From the source code I see
FindNextSibling
callsr.Pointer.NextSibling.NextSibling
which wrongly assumesNextSibling
should have anotherNextSibling
, and crash when it does not.e.g.
This also applies for
FindPrevSibling
.BTW, I suggest there should be
FindNextSibling
andFindNextSiblingElement
as the spec describes. (This might be another issue, I guess what you want to implement isFindNextSiblingElement
.)