Skip to content

Commit b3bf673

Browse files
committed
Throw parse ex on invalid quoted selector
1 parent 9d3f82c commit b3bf673

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/main/java/org/jsoup/select/Evaluator.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,10 @@ public AttributeKeyPair(String key, String value) {
426426
this.key = normalize(key);
427427
boolean quoted = value.startsWith("'") && value.endsWith("'")
428428
|| value.startsWith("\"") && value.endsWith("\"");
429-
if (quoted)
429+
if (quoted) {
430+
Validate.isTrue(value.length() > 1, "Quoted value must have content");
430431
value = value.substring(1, value.length() - 1);
432+
}
431433

432434
this.value = lowerCase(value); // case-insensitive match
433435
}

src/test/java/org/jsoup/select/SelectorTest.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1768,7 +1768,7 @@ public void testAncestorChain() {
17681768
assertSelectedIds(doc.select("div[data*='']"), "1", "2", "3");
17691769
}
17701770

1771-
@Test void parseExceptionOnEmptyUrl() {
1771+
@Test void parseExceptionOnEmptyAbsKey() {
17721772
// was previously firing at match time, not eval time
17731773
String q = "[abs:!=]";
17741774
boolean threw = false;
@@ -1781,4 +1781,17 @@ public void testAncestorChain() {
17811781
assertTrue(threw);
17821782
}
17831783

1784+
@Test void parseExceptionOnEmptyKeyVal() {
1785+
// was previously firing at match time, not eval time
1786+
String q = "[\"=\"]";
1787+
boolean threw = false;
1788+
try {
1789+
Evaluator e = Selector.evaluatorOf(q);
1790+
} catch (Selector.SelectorParseException ex) {
1791+
threw = true;
1792+
assertEquals("Quoted value must have content", ex.getMessage());
1793+
}
1794+
assertTrue(threw);
1795+
}
1796+
17841797
}

0 commit comments

Comments
 (0)