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

Already on GitHub? Sign in to your account

StringIndexOutOfBoundsException when testing whether String content is valid HTML #32

timezra opened this Issue Aug 11, 2010 · 2 comments


None yet
2 participants

timezra commented Aug 11, 2010

If I try to parse a tag with an equals sign (an empty attribute) but without any single or double quotes around an attribute value, then I get a StringIndexOutOfBoundsException. The stack trace is pasted below.

An example String would be "<a =a"

The following JUnit test case should not throw a StringIndexOutOfBoundsException:

import static org.junit.Assert.assertTrue;
import org.jsoup.Jsoup;
import org.jsoup.safety.Whitelist;
import org.junit.Test;
public class BadAttributeTest {
public void aTagWithABadAttributeIsValid() throws Exception {
assertTrue(Jsoup.isValid("<a =a", Whitelist.relaxed()));

java.lang.StringIndexOutOfBoundsException: String index out of range: 13
at java.lang.String.charAt(String.java:686)
at org.jsoup.parser.TokenQueue.consume(TokenQueue.java:130)
at org.jsoup.parser.Parser.parseAttribute(Parser.java:207)
at org.jsoup.parser.Parser.parseStartTag(Parser.java:142)
at org.jsoup.parser.Parser.parse(Parser.java:91)
at org.jsoup.parser.Parser.parseBodyFragment(Parser.java:64)
at org.jsoup.Jsoup.parseBodyFragment(Jsoup.java:99)
at org.jsoup.Jsoup.isValid(Jsoup.java:155)


jhy commented Aug 11, 2010

Thanks, well spotted. I'll fix that for the next release.


jhy commented Aug 13, 2010

Fixed issue when parsing tags with keyless attributes.

Closed by 856c8ef

@michael-simons michael-simons pushed a commit to michael-simons/jsoup that referenced this issue Jul 12, 2011

@jhy jhy Fixed issue when parsing tags with keyless attributes.
Fixes #32

@zazi zazi pushed a commit to dswarm/jsoup that referenced this issue Oct 15, 2015

@jhy jhy Fixed issue when parsing tags with keyless attributes.
Fixes #32

This issue was closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment