diff --git a/src/main/java/org/jsoup/parser/TokenQueue.java b/src/main/java/org/jsoup/parser/TokenQueue.java index f70886169d..2c12284155 100644 --- a/src/main/java/org/jsoup/parser/TokenQueue.java +++ b/src/main/java/org/jsoup/parser/TokenQueue.java @@ -201,13 +201,16 @@ public String consumeToIgnoreCase(String seq) { int start = pos; String first = seq.substring(0, 1); boolean canScan = first.toLowerCase().equals(first.toUpperCase()); // if first is not cased, use index of - while (!isEmpty() && !matches(seq)) { + while (!isEmpty()) { + if (matches(seq)) + break; + if (canScan) { int skip = queue.indexOf(first, pos) - pos; - if (skip <= 0) + if (skip == 0) // this char is the skip char, but not match, so force advance of pos pos++; else if (skip < 0) // no chance of finding, grab to end - pos = queue.length() - 1; + pos = queue.length(); else pos += skip; }