Skip to content

Commit c42f4c3

Browse files
committed
Error vs throw if the insert after el was no longer on the stack
Fixes #2393
1 parent 5909b8f commit c42f4c3

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Previously cached child Elements of an Element were not correctly invalidated in `Node#replaceWith(Node)`, which could lead to incorrect results when subsequently calling `Element#children()`. [#2391](https://github.com/jhy/jsoup/issues/2391)
77
* Attribute selector values are now compared literally without trimming. Previously, jsoup trimmed whitespace from selector values and from element attribute values, which could cause mismatches with browser behavior (e.g. `[attr=" foo "]`). Now matches align with the CSS specification and browser engines. [#2380](https://github.com/jhy/jsoup/issues/2380)
88
* When using the JDK HttpClient, any system default proxy (`ProxySelector.getDefault()`) was ignored. Now, the system proxy is used if a per-request proxy is not set. [#2388](https://github.com/jhy/jsoup/issues/2388), [#2390](https://github.com/jhy/jsoup/pull/2390)
9+
* A ValidationException could be thrown in the adoption agency algorithm with particularly broken input. Now logged as a parse error. [#2393](https://github.com/jhy/jsoup/issues/2393)
910

1011

1112
## 1.21.2 (2025-Aug-25)

src/main/java/org/jsoup/parser/HtmlTreeBuilder.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,8 +558,13 @@ private void clearStackToContext(String... nodeNames) {
558558

559559
void insertOnStackAfter(Element after, Element in) {
560560
int i = stack.lastIndexOf(after);
561-
Validate.isTrue(i != -1);
562-
stack.add(i+1, in);
561+
if (i == -1) {
562+
error("Did not find element on stack to insert after");
563+
stack.add(in);
564+
// may happen on particularly malformed inputs during adoption
565+
} else {
566+
stack.add(i+1, in);
567+
}
563568
}
564569

565570
void replaceOnStack(Element out, Element in) {
377 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)