Skip to content

Commit

Permalink
UTF-16 not supported
Browse files Browse the repository at this point in the history
Fixes eclipse-lemminx#611

Signed-off-by: azerr <azerr@redhat.com>
  • Loading branch information
angelozerr committed Mar 9, 2020
1 parent 4d154e4 commit c56013b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public enum XMLSyntaxErrorCode implements IXMLErrorCode {

AttributeNotUnique, // https://wiki.xmldation.com/Support/Validator/AttributeNotUnique
AttributeNSNotUnique, // https://wiki.xmldation.com/Support/Validator/AttributeNSNotUnique
AttributePrefixUnbound, ContentIllegalInProlog, // https://wiki.xmldation.com/Support/Validator/ContentIllegalInProlog
AttributePrefixUnbound, //
ContentIllegalInProlog, // https://wiki.xmldation.com/Support/Validator/ContentIllegalInProlog
DashDashInComment, // https://wiki.xmldation.com/Support/Validator/DashDashInComment
ElementUnterminated, // https://wiki.xmldation.com/Support/Validator/ElementUnterminated
ElementPrefixUnbound, // https://wiki.xmldation.com/Support/Validator/ElementPrefixUnbound
Expand All @@ -55,7 +56,8 @@ public enum XMLSyntaxErrorCode implements IXMLErrorCode {
LessthanInAttValue, MarkupEntityMismatch, MarkupNotRecognizedInContent, NameRequiredInReference, OpenQuoteExpected,
PITargetRequired, PseudoAttrNameExpected, QuoteRequiredInXMLDecl, RootElementTypeMustMatchDoctypedecl,
SDDeclInvalid, SpaceRequiredBeforeEncodingInXMLDecl, SpaceRequiredBeforeStandalone, SpaceRequiredInPI,
VersionInfoRequired, VersionNotSupported, XMLDeclUnterminated, CustomETag, PrematureEOF, DoctypeNotAllowed, NoMorePseudoAttributes;
VersionInfoRequired, VersionNotSupported, XMLDeclUnterminated, CustomETag, PrematureEOF, DoctypeNotAllowed,
NoMorePseudoAttributes;

private final String code;

Expand Down Expand Up @@ -167,8 +169,23 @@ public static Range toLSPRange(XMLLocator location, XMLSyntaxErrorCode code, Obj
return XMLPositionUtility.selectChildEndTag(tag, offset, document);
}
case ContentIllegalInProlog: {
int endOffset = document.getText().indexOf("<");
int startOffset = offset + 1;
int startOffset = 0;
int endOffset = 0;
int errorOffset = offset + 1;
String text = document.getText();
int startPrologOffset = text.indexOf("<");
if (errorOffset < startPrologOffset) {
// Invalid content given before prolog. Prolog should be the first thing in the
// file if given.
startOffset = errorOffset;
endOffset = startPrologOffset;
} else {
// Invalid content given after prolog. Either root tag or comment should be
// present
int firstStartTagOffset = text.indexOf("<", errorOffset);
startOffset = errorOffset;
endOffset = firstStartTagOffset != -1 ? firstStartTagOffset : text.length();
}
return XMLPositionUtility.createRange(startOffset, endOffset, document);
}
case DashDashInComment: {
Expand All @@ -189,7 +206,7 @@ public static Range toLSPRange(XMLLocator location, XMLSyntaxErrorCode code, Obj
}
case DoctypeNotAllowed:
DOMDocumentType docType = document.getDoctype();
return XMLPositionUtility.createRange(docType);
return XMLPositionUtility.createRange(docType);
case PITargetRequired:
// Working
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,35 @@ public void testAttributePrefixUnbound() throws Exception {
* @throws Exception
*/
@Test
public void testContentIllegalInProlog() throws Exception {
public void testBeforeContentIllegalInProlog() throws Exception {
String xml = " ab?<xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>";
testDiagnosticsFor(xml, d(0, 1, 0, 4, XMLSyntaxErrorCode.ContentIllegalInProlog));
}

/**
* ContentIllegalInProlog tests
*
* @see https://wiki.xmldation.com/Support/Validator/ContentIllegalInProlog
* @throws Exception
*/
@Test
public void testAfterContentIllegalInProlog() throws Exception {
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>ab\ncd";
testDiagnosticsFor(xml, d(0, 54, 1, 2, XMLSyntaxErrorCode.ContentIllegalInProlog));
}

/**
* ContentIllegalInProlog tests
*
* @see https://wiki.xmldation.com/Support/Validator/ContentIllegalInProlog
* @throws Exception
*/
@Test
public void testAfterContentIllegalInProlog2() throws Exception {
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>ab\ncd<root>";
testDiagnosticsFor(xml, d(0, 54, 1, 2, XMLSyntaxErrorCode.ContentIllegalInProlog));
}

/**
* DashDashInComment tests
*
Expand Down

0 comments on commit c56013b

Please # to comment.