Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IndexOutOfBoundsException while trying to insert nested paragraphs and links #1602

Closed
kokorins opened this issue Jul 31, 2021 · 2 comments
Closed
Assignees
Labels
bug Confirmed bug that we should fix
Milestone

Comments

@kokorins
Copy link

val bareFragment = "<p></p><a></a>"
Document("").parser().parseFragmentInput(bareFragment, Element("p"), "")

ends up with

java.lang.IndexOutOfBoundsException: Index -1 out of bounds for length 1
	at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
	at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
	at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248)
	at java.base/java.util.Objects.checkIndex(Objects.java:373)
	at java.base/java.util.ArrayList.get(ArrayList.java:427)
	at org.jsoup.parser.HtmlTreeBuilderState$7.inBodyEndTagAdoption(HtmlTreeBuilderState.java:814)
	at org.jsoup.parser.HtmlTreeBuilderState$7.inBodyEndTag(HtmlTreeBuilderState.java:731)
	at org.jsoup.parser.HtmlTreeBuilderState$7.process(HtmlTreeBuilderState.java:288)
	at org.jsoup.parser.HtmlTreeBuilder.process(HtmlTreeBuilder.java:149)
	at org.jsoup.parser.TreeBuilder.runParser(TreeBuilder.java:76)
	at org.jsoup.parser.HtmlTreeBuilder.parseFragment(HtmlTreeBuilder.java:133)
	at org.jsoup.parser.Parser.parseFragmentInput(Parser.java:53)
@krystiangorecki
Copy link
Contributor

Reproducible using 1.14.1, but using 1.13.1 I get NPE because parser() returns null.

String bareFragment = "<p></p><a></a>";
new Document("").parser().parseFragmentInput(bareFragment, new Element("p"), "");

@jhy jhy self-assigned this Aug 4, 2021
@jhy jhy added the bug Confirmed bug that we should fix label Aug 4, 2021
@jhy jhy added this to the 1.14.2 milestone Aug 4, 2021
@jhy jhy closed this as completed in d6a4d20 Aug 4, 2021
@jhy
Copy link
Owner

jhy commented Aug 4, 2021

Thanks, fixed! Let me know if you find other issues around these parse fragments; there are clearly some edge-case bugs here because there's nothing else on the stack when created this way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bug that we should fix
Projects
None yet
Development

No branches or pull requests

3 participants