From 3091b666a672aba7281e29d919f5c940380ef846 Mon Sep 17 00:00:00 2001 From: Jonathan Hedley Date: Tue, 24 Jan 2023 09:43:30 +1100 Subject: [PATCH] Iterate vs recurse to find the deepest child Removes chance of overflow in wrap(html) and simplifies. Related to #1864 --- src/main/java/org/jsoup/nodes/Node.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/jsoup/nodes/Node.java b/src/main/java/org/jsoup/nodes/Node.java index 40c9b16a1e..60f9942007 100644 --- a/src/main/java/org/jsoup/nodes/Node.java +++ b/src/main/java/org/jsoup/nodes/Node.java @@ -449,11 +449,10 @@ public Node wrap(String html) { } private Element getDeepChild(Element el) { - List children = el.children(); - if (children.size() > 0) - return getDeepChild(children.get(0)); - else - return el; + while (el.childrenSize() > 0) { + el = el.childElementsList().get(0); + } + return el; } void nodelistChanged() {