Skip to content

Commit

Permalink
Fix error range for ETagRequired
Browse files Browse the repository at this point in the history
Fixes #387

Signed-off-by: David Kwon <[email protected]>
  • Loading branch information
dkwon17 authored and fbricon committed May 30, 2019
1 parent f9d5253 commit d64c771
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,20 +178,32 @@ public static Range selectChildEndTag(String childTag, int offset, DOMDocument d
if (parent == null || !parent.isElement() || ((DOMElement) parent).getTagName() == null) {
return null;
}
if (parent != null) {
DOMNode child = findChildNode(childTag, parent.getChildren());
if (child != null) {

DOMNode curr = parent;
DOMNode child;
while (curr != null) {
child = findUnclosedChildNode(childTag, curr.getChildren());
if (child == null) {
curr = findUnclosedChildNode(curr.getChildren());
} else {
return createRange(child.getStart() + 1, child.getStart() + 1 + childTag.length(), document);
}
if(parent.isElement()) {
String parentName = ((DOMElement) parent).getTagName();
return createRange(parent.getStart() + 2, parent.getStart() + 2 + parentName.length(), document);
}

String parentName = ((DOMElement) parent).getTagName();
return createRange(parent.getStart() + 2, parent.getStart() + 2 + parentName.length(), document);
}

public static DOMNode findUnclosedChildNode(List<DOMNode> children) {
for (DOMNode child: children) {
if (!child.isClosed()) {
return child;
}
}
return null;
}

static DOMNode findChildNode(String childTag, List<DOMNode> children) {
static DOMNode findUnclosedChildNode(String childTag, List<DOMNode> children) {
for (DOMNode child : children) {
if (child.isElement() && childTag != null && childTag.equals(((DOMElement) child).getTagName())
&& !child.isClosed()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,16 @@ public void testETagRequired2() throws Exception {
testDiagnosticsFor(xml, d(1, 13, 1, 15, XMLSyntaxErrorCode.ETagRequired));
}

@Test
public void testETagRequired3() throws Exception {
String xml = "<UltmtDbtr>\r\n" +
" <Nm>Name</Nm>\r\n" +
" <Ad>\r\n" +
" <Ph>\r\n" +
"</UltmtDbtr>";
testDiagnosticsFor(xml, d(3, 5, 3, 7, XMLSyntaxErrorCode.ETagRequired));
}

/**
* Test ETagUnterminated
*
Expand Down

0 comments on commit d64c771

Please sign in to comment.