Skip to content

Commit

Permalink
Prevent NPE in HtmlAttributes.getIndex
Browse files Browse the repository at this point in the history
Apparently it’s possible for a “mode” value to be such that
AttributeName.getQName(mode) returns null. So this change adds a null
check to catch that.

Otherwise, without this change, some documents cause that code to throw
a NullPointerException.
  • Loading branch information
sideshowbarker committed Feb 20, 2024
1 parent 15073af commit 5b619ab
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/nu/validator/htmlparser/impl/HtmlAttributes.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ public AttributeName getAttributeNameNoBoundsCheck(int index) {

public int getIndex(String qName) {
for (int i = 0; i < length; i++) {
if (names[i].getQName(mode).equals(qName)) {
if (names[i].getQName(mode) != null &&
names[i].getQName(mode).equals(qName)) {
return i;
}
}
Expand Down

0 comments on commit 5b619ab

Please sign in to comment.