skrapeit/skrape.it

[BUG] Children of a DocElement from a relaxed Doc should also be relaxed.

danisty opened this issue · 2 comments

Describe the bug
Getting the children of a Doc/DocElement will call the public constructor of DocElement and set relaxed to false, thus making all children throw an exception if a query selection fails.

Also happens for siblings, allElements and parents.

Code Sample

val doc = htmlDocument("<div>skrape<b>it</b></div>")
doc.relaxed = true

doc.findFirst("b").findFirst("a") // Will not throw an exception
doc.children[0].findFirst("a") // Will throw an exception
// it.skrape.selects.ElementNotFoundException: Could not find element "a"

public val children: List<DocElement> by lazy {
element.children().map { DocElement(it) }
}
public class DocElement internal constructor(
override val element: Element,
override val relaxed: Boolean
) : DomTreeElement() {
public constructor(element: Element) : this(element, false)

Expected behavior
Inherit the relaxed property.

I'd like to reopen this issue since the merged pr doesn't fix it. The relaxed property should be passed to the DocElement constructor for the methods mentioned before: children, siblings, allElements and parents.

Ok thanks for pointing this out 👍