Skip to content

Commit

Permalink
Relax validator to support [^] any attribute prefix
Browse files Browse the repository at this point in the history
This discovered functionality previously worked.

Relates to #2079
  • Loading branch information
jhy committed Dec 17, 2023
1 parent 8a4bdae commit 3375e1c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/org/jsoup/select/Evaluator.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public static final class AttributeStarting extends Evaluator {
private final String keyPrefix;

public AttributeStarting(String keyPrefix) {
Validate.notEmpty(keyPrefix);
Validate.notNull(keyPrefix); // OK to be empty - will find elements with any attributes
this.keyPrefix = lowerCase(keyPrefix);
}

Expand Down
13 changes: 13 additions & 0 deletions src/test/java/org/jsoup/select/SelectorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1230,4 +1230,17 @@ public void wildcardNamespaceMatchesNoNamespace() {
Elements els = doc.select(q);
assertEquals(3, els.size());
}

@Test public void emptyAttributePrefix() {
// https://github.com/jhy/jsoup/issues/2079
// Discovered feature: [^] should find elements with any attribute (any prefix)
String html = "<p one>One<p one two>Two<p>Three";
Document doc = Jsoup.parse(html);

Elements els = doc.select("[^]");
assertSelectedOwnText(els, "One", "Two");

Elements emptyAttr = doc.select("p:not([^])");
assertSelectedOwnText(emptyAttr, "Three");
}
}

0 comments on commit 3375e1c

Please sign in to comment.