Skip to content

Commit

Permalink
Test that wrap() can't overflow
Browse files Browse the repository at this point in the history
Related to #1864
  • Loading branch information
jhy committed Jan 24, 2023
1 parent 3091b66 commit 9d104b7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ Release 1.15.4 [PENDING]
* Bugfix: fixed an issue in Safelist.removeAttributes which could throw a ConcurrentModificationException when using
the ":all" pseudo-attribute.

* Bugfix: given extremely deeply nested HTML, a number of methods in Element could throw a StackOverflowError due
to excessive recursion. Namely: #data(), #hasText(), #parents(), and #wrap(html).
<https://github.com/jhy/jsoup/issues/1864>

* Change: deprecated the unused Document#normalise() method. Normalization occurs during the HTML tree construction,
and no longer as a distinct phase.

Expand Down
15 changes: 15 additions & 0 deletions src/test/java/org/jsoup/nodes/ElementIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,19 @@ public void testFastReparentExistingContent() {
assertEquals(num+2, parents.size()); // +2 for html and body
assertEquals(doc, el.ownerDocument());
}

@Test void wrapNoOverflow() {
// deepChild was recursive, so could overflow if presented with a fairly insane wrap
Document doc = new Document("https://example.com/");
Element el = doc.body().appendElement("p");
int num = 50000;
StringBuilder sb = new StringBuilder();
for (int i = 0; i <= num; i++) {
sb.append("<div>");
}
el.wrap(sb.toString());
String html = doc.body().html();
assertTrue(html.startsWith("<div>"));
assertEquals(num + 3, el.parents().size());
}
}

0 comments on commit 9d104b7

Please sign in to comment.