Fix bug with validator hanging on some XML instances

This commit is contained in:
Grahame Grieve 2022-09-07 08:11:09 +10:00
parent 44aeaa1a80
commit c3ab401f56
1 changed files with 8 additions and 7 deletions

View File

@ -307,15 +307,16 @@ public class XmlParser extends ParserBase {
Node n = node.getFirstChild(); Node n = node.getFirstChild();
while (n != null) { while (n != null) {
if (n.getNodeType() == Node.TEXT_NODE && !Utilities.noString(n.getTextContent().trim())) { if (n.getNodeType() == Node.TEXT_NODE && !Utilities.noString(n.getTextContent().trim())) {
while (n.getNextSibling() != null && n.getNodeType() != Node.ELEMENT_NODE) { Node nt = n;
n = n.getNextSibling(); while (nt.getNextSibling() != null && nt.getNodeType() != Node.ELEMENT_NODE) {
nt = nt.getNextSibling();
} }
while (n.getPreviousSibling() != null && n.getNodeType() != Node.ELEMENT_NODE) { while (nt.getPreviousSibling() != null && nt.getNodeType() != Node.ELEMENT_NODE) {
n = n.getPreviousSibling(); nt = nt.getPreviousSibling();
} }
line = line(n); line = line(nt);
col = col(n); col = col(nt);
logError(line, col, path, IssueType.STRUCTURE, context.formatMessage(I18nConstants.TEXT_SHOULD_NOT_BE_PRESENT, text), IssueSeverity.ERROR); logError(line, col, path, IssueType.STRUCTURE, context.formatMessage(I18nConstants.TEXT_SHOULD_NOT_BE_PRESENT, Utilities.makeSingleLine(text)), IssueSeverity.ERROR);
} }
n = n.getNextSibling(); n = n.getNextSibling();
} }