mirror of
https://github.com/yuin/goldmark
synced 2025-03-04 23:04:52 +00:00
fix bug: if do c.SetNextSibling(nil) and c = c.NextSibling(). After remove the first child the var c is always nil.the next child will not be set nil
This commit is contained in:
parent
3e38e966f6
commit
4fc27178e4
2 changed files with 21 additions and 1 deletions
|
|
@ -236,10 +236,12 @@ func (n *BaseNode) RemoveChild(self, v Node) {
|
|||
|
||||
// RemoveChildren implements Node.RemoveChildren .
|
||||
func (n *BaseNode) RemoveChildren(self Node) {
|
||||
for c := n.firstChild; c != nil; c = c.NextSibling() {
|
||||
for c := n.firstChild; c != nil; {
|
||||
c.SetParent(nil)
|
||||
c.SetPreviousSibling(nil)
|
||||
next := c.NextSibling()
|
||||
c.SetNextSibling(nil)
|
||||
c = next
|
||||
}
|
||||
n.firstChild = nil
|
||||
n.lastChild = nil
|
||||
|
|
|
|||
18
ast/ast_test.go
Normal file
18
ast/ast_test.go
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
package ast
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestRemoveChildren(t *testing.T) {
|
||||
root := NewDocument()
|
||||
|
||||
node1 := NewDocument()
|
||||
|
||||
node2 := NewDocument()
|
||||
|
||||
root.AppendChild(root, node1)
|
||||
root.AppendChild(root, node2)
|
||||
|
||||
root.RemoveChildren(root)
|
||||
|
||||
t.Logf("%+v", node2.PreviousSibling())
|
||||
}
|
||||
Loading…
Reference in a new issue