Skip to content

Commit

Permalink
ClassCastException: with documentLink in catalog
Browse files Browse the repository at this point in the history
XMLCatalogDocumentLinkParticipant

Fixes eclipse-lemminx#932

Signed-off-by: azerr <azerr@redhat.com>
  • Loading branch information
angelozerr authored and datho7561 committed Dec 8, 2020
1 parent 31e88e1 commit fdccc76
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static List<CatalogEntry> getCatalogEntries(DOMDocument document) {
return Collections.emptyList();
}
for (DOMNode n : document.getChildren()) {
if (CATALOG_ENTITY_NAME.equals(n.getNodeName())) {
if (n.isElement() && CATALOG_ENTITY_NAME.equals(n.getNodeName())) {
return collectCatalogEntries((DOMElement) n);
}
}
Expand Down Expand Up @@ -178,11 +178,13 @@ private static List<CatalogEntry> collectGroupEntries(DOMElement group, @NonNull
}

/**
* Returns a catalog entry for the given element and null if a catalog entry can't be made
* Returns a catalog entry for the given element and null if a catalog entry
* can't be made
*
* @param baseURI the base URI of the catalog entry
* @param element the element to turn into a catalog entry
* @return a catalog entry for the given element and null if a catalog entry can't be made
* @return a catalog entry for the given element and null if a catalog entry
* can't be made
*/
private static CatalogEntry createCatalogEntry(@NonNull String baseURI, DOMElement element) {
if (isCatalogEntryWithURI(element)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@

package org.eclipse.lemminx.extensions.catalog;

import org.junit.jupiter.api.Test;

import static org.eclipse.lemminx.XMLAssert.testDocumentLinkFor;
import static org.eclipse.lemminx.XMLAssert.dl;
import static org.eclipse.lemminx.XMLAssert.r;
import static org.eclipse.lemminx.XMLAssert.testDocumentLinkFor;

import org.junit.jupiter.api.Test;

/**
* Tests for the document links in XML catalog files
Expand Down Expand Up @@ -53,6 +53,21 @@ public void testURIEntryDocumentLink() {
dl(r(3, 9, 3, 23), "src/test/resources/neatSchema.xsd"));
}

@Test
public void testCatalogWithCatalogDOCTYPE() {
String xml = "<!DOCTYPE catalog PUBLIC \"-//OASIS//DTD XML Catalogs V1.1//EN\" \"catalog.dtd\" >\n"
+ //
"<catalog xmlns=\"urn:oasis:names:tc:entity:xmlns:xml:catalog\">\n" + //
" <uri\n" + //
" id=\"http://example.org\"\n" + //
" uri=\"neatSchema.xsd\" />\n" + //
"</catalog>";
testDocumentLinkFor(xml, CATALOG_PATH, //
dl(r(0, 64, 0, 75), "src/test/resources/catalog.dtd"), //
dl(r(4, 9, 4, 23), "src/test/resources/neatSchema.xsd"));

}

@Test
public void testSystemSuffixEntryDocumentLink() {
String xml = "<catalog xmlns=\"urn:oasis:names:tc:entity:xmlns:xml:catalog\">\n" + //
Expand Down

0 comments on commit fdccc76

Please sign in to comment.