scinfu / SwiftSoup

SwiftSoup: Pure Swift HTML Parser, with best of DOM, CSS, and jquery (Supports Linux, iOS, Mac, tvOS, watchOS)
https://scinfu.github.io/SwiftSoup/
MIT License
4.52k stars 345 forks source link

Support NodeVisitor.tail() removing Node #247

Closed mkscrg closed 1 year ago

mkscrg commented 1 year ago

Currently, NodeTraversor crashes when its NodeVisitor removes the current Node from tail(). This change safeguards that behavior by bookkeeping .parent() and .nextSibling() inside the traversal loop.

Also added a test class for NodeTraversor with a test for head() and tail() traversal order.

mkscrg commented 1 year ago

This could be extended to allow the same behavior in head(), but the bookkeeping is trickier!

scinfu commented 1 year ago

thank you