Skip to content

Commit

Permalink
Merge pull request #259 from tid-kijyun/fix/cleanup_when_removing_a_node
Browse files Browse the repository at this point in the history
Fixed cleanup when removing a node
  • Loading branch information
tid-kijyun authored Dec 1, 2021
2 parents 16f8eb7 + 4c7a9d6 commit 73c5e8a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/Kanna/libxmlHTMLNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ final class libxmlHTMLNode: XMLElement {
return
}
xmlUnlinkNode(node.nodePtr)
xmlFree(node.nodePtr)
xmlFreeNode(node.nodePtr)
}

private func node(from ptr: xmlNodePtr?) -> XMLElement? {
Expand Down
16 changes: 16 additions & 0 deletions Tests/KannaTests/KannaHTMLModifyingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@ class KannaHTMLModifyingTests: XCTestCase {
XCTAssert(doc.body!.toHTML == modifyNextHTML)
}
}

func testHTML_RemoveNode() {
let html = "<body><div>A love triangle.<h1>Three's Company</h1></div></body>"

let removedHTML = "<body><div>A love triangle.</div></body>"

do {
guard let doc = try? HTML(html: html, encoding: .utf8),
let h1 = doc.at_css("h1") else {
return
}

doc.body?.removeChild(h1)
XCTAssert(doc.body!.toHTML == removedHTML)
}
}
}

extension KannaHTMLModifyingTests {
Expand Down

0 comments on commit 73c5e8a

Please sign in to comment.