Merge branch 'remove-xml-dom-rule' into core-parser-tasks
This commit is contained in:
@ -4,6 +4,7 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.xml.ast.internal;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.util.HashMap;
|
||||
@ -14,6 +15,7 @@ import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
import org.xml.sax.EntityResolver;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
@ -25,6 +27,8 @@ import net.sourceforge.pmd.lang.xml.ast.XmlNode;
|
||||
|
||||
|
||||
public final class XmlParserImpl {
|
||||
// never throws on unresolved resource
|
||||
private static final EntityResolver SILENT_ENTITY_RESOLVER = (publicId, systemId) -> new InputSource(new ByteArrayInputStream("".getBytes()));
|
||||
|
||||
private final Map<org.w3c.dom.Node, XmlNode> nodeCache = new HashMap<>();
|
||||
|
||||
@ -44,6 +48,7 @@ public final class XmlParserImpl {
|
||||
dbf.setFeature("http://xml.org/sax/features/external-general-entities", false);
|
||||
dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
|
||||
DocumentBuilder documentBuilder = dbf.newDocumentBuilder();
|
||||
documentBuilder.setEntityResolver(SILENT_ENTITY_RESOLVER);
|
||||
return documentBuilder.parse(new InputSource(new StringReader(xmlData)));
|
||||
} catch (ParserConfigurationException | SAXException | IOException e) {
|
||||
throw new ParseException(e);
|
||||
|
@ -4,14 +4,13 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.xml.ast;
|
||||
|
||||
import static net.sourceforge.pmd.lang.ast.test.TestUtilsKt.assertPosition;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.junit.Test;
|
||||
|
||||
import net.sourceforge.pmd.lang.ast.test.BaseParsingHelper;
|
||||
import net.sourceforge.pmd.lang.ast.test.BaseTreeDumpTest;
|
||||
import net.sourceforge.pmd.lang.ast.test.CoordinatesPrinter;
|
||||
import net.sourceforge.pmd.lang.ast.test.TestUtilsKt;
|
||||
import net.sourceforge.pmd.lang.xml.XmlParsingHelper;
|
||||
|
||||
public class XmlCoordinatesTest extends BaseTreeDumpTest {
|
||||
@ -37,7 +36,7 @@ public class XmlCoordinatesTest extends BaseTreeDumpTest {
|
||||
@Test
|
||||
public void testAutoclosingElementLength() {
|
||||
final String xml = "<elementName att1='foo' att2='bar' att3='other' />";
|
||||
assertPosition(XmlParsingHelper.XML.parse(xml), 1, 1, 1, xml.length());
|
||||
TestUtilsKt.assertPosition(XmlParsingHelper.XML.parse(xml), 1, 1, 1, xml.length());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -40,4 +40,29 @@ public class XmlParserTest extends BaseTreeDumpTest {
|
||||
public void testBug1518() {
|
||||
doTest("bug1518");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void dtdIsNotLookedUp() {
|
||||
// no exception should be thrown
|
||||
XmlParsingHelper.XML.parse(
|
||||
"<!DOCTYPE struts-config PUBLIC "
|
||||
+ " \"-//Apache Software Foundation//DTD Struts Configuration 1.1//EN \" "
|
||||
+ " \"http://jakarta.inexistinghost.org/struts/dtds/struts-config_1_1.dtd\" >"
|
||||
+ "<struts-config/>");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void xsdIsNotLookedUp() {
|
||||
// no exception should be thrown
|
||||
XmlParsingHelper.XML.parse(
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?> "
|
||||
+ "<web-app xmlns=\"http://java.sun.com/xml/ns/javaee\" "
|
||||
+ "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
|
||||
+ "xsi:schemaLocation=\"http://java.sun.com/xml/ns/javaee http://java.inexisting.com/xml/ns/javaee/web-app_2_5.xsd\" "
|
||||
+ "version=\"2.5\">"
|
||||
+ "</web-app>");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,69 +1,48 @@
|
||||
+- document[]
|
||||
+- deployment-plan[@global-variables = "false", @xmlns = "http://xmlns.oracle.com/weblogic/deployment-plan", @xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance", @xsi:schemaLocation = "http://xmlns.oracle.com/weblogic/deployment-plan http://xmlns.oracle.com/weblogic/deployment-plan/1.0/deployment-plan.xsd"]
|
||||
+- text[@Image = "
|
||||
"]
|
||||
+- text[@Image = "\n "]
|
||||
+- application-name[]
|
||||
| +- text[@Image = "app"]
|
||||
+- text[@Image = "
|
||||
"]
|
||||
+- text[@Image = "\n "]
|
||||
+- variable-definition[]
|
||||
| +- text[@Image = "
|
||||
"]
|
||||
| +- text[@Image = "\n "]
|
||||
| +- variable[]
|
||||
| | +- text[@Image = "
|
||||
"]
|
||||
| | +- text[@Image = "\n "]
|
||||
| | +- name[]
|
||||
| | | +- text[@Image = "Application_Module_Web_ContextRoot"]
|
||||
| | +- text[@Image = "
|
||||
"]
|
||||
| | +- text[@Image = "\n "]
|
||||
| | +- value[@xsi:nil = "false"]
|
||||
| | | +- text[@Image = "ikb.adf.kreda.abw.webapp-Abnahmetest-ohne-SSO"]
|
||||
| | +- text[@Image = "
|
||||
"]
|
||||
| +- text[@Image = "
|
||||
"]
|
||||
+- text[@Image = "
|
||||
"]
|
||||
| | +- text[@Image = "\n "]
|
||||
| +- text[@Image = "\n "]
|
||||
+- text[@Image = "\n "]
|
||||
+- module-override[]
|
||||
| +- text[@Image = "
|
||||
"]
|
||||
| +- text[@Image = "\n "]
|
||||
| +- module-name[]
|
||||
| | +- text[@Image = "ikb.adf.kreda.abw.ear"]
|
||||
| +- text[@Image = "
|
||||
"]
|
||||
| +- text[@Image = "\n "]
|
||||
| +- module-type[]
|
||||
| | +- text[@Image = "ear"]
|
||||
| +- text[@Image = "
|
||||
"]
|
||||
| +- text[@Image = "\n "]
|
||||
| +- module-descriptor[@external = "false"]
|
||||
| | +- text[@Image = "
|
||||
"]
|
||||
| | +- text[@Image = "\n "]
|
||||
| | +- root-element[]
|
||||
| | | +- text[@Image = "application"]
|
||||
| | +- text[@Image = "
|
||||
"]
|
||||
| | +- text[@Image = "\n "]
|
||||
| | +- uri[]
|
||||
| | | +- text[@Image = "META-INF/application.xml"]
|
||||
| | +- text[@Image = "
|
||||
"]
|
||||
| | +- text[@Image = "\n "]
|
||||
| | +- variable-assignment[]
|
||||
| | | +- text[@Image = "
|
||||
"]
|
||||
| | | +- text[@Image = "\n "]
|
||||
| | | +- name[]
|
||||
| | | | +- text[@Image = "Application_Module_Web_ContextRoot"]
|
||||
| | | +- text[@Image = "
|
||||
"]
|
||||
| | | +- text[@Image = "\n "]
|
||||
| | | +- xpath[]
|
||||
| | | | +- text[@Image = "/application/module/web/[context-root="ikb.adf.kreda.abw.webapp-Local-ohne-SSO"]"]
|
||||
| | | +- text[@Image = "
|
||||
"]
|
||||
| | | | +- text[@Image = "/application/module/web/[context-root=\"ikb.adf.kreda.abw.webapp-Local-ohne-SSO\"]"]
|
||||
| | | +- text[@Image = "\n "]
|
||||
| | | +- operation[]
|
||||
| | | | +- text[@Image = "replace"]
|
||||
| | | +- text[@Image = "
|
||||
"]
|
||||
| | +- text[@Image = "
|
||||
"]
|
||||
| +- text[@Image = "
|
||||
"]
|
||||
+- text[@Image = "
|
||||
"]
|
||||
| | | +- text[@Image = "\n "]
|
||||
| | +- text[@Image = "\n "]
|
||||
| +- text[@Image = "\n "]
|
||||
+- text[@Image = "\n"]
|
||||
|
@ -2,21 +2,14 @@
|
||||
+- comment[]
|
||||
+- rootElement[]
|
||||
+- rootElement[]
|
||||
+- text[@Image = "
|
||||
"]
|
||||
+- text[@Image = "\n "]
|
||||
+- comment[]
|
||||
+- text[@Image = "
|
||||
"]
|
||||
+- text[@Image = "\n "]
|
||||
+- child1[@test = "1"]
|
||||
| +- text[@Image = "entity: Copyright: PMD
|
||||
"]
|
||||
+- text[@Image = "
|
||||
"]
|
||||
| +- text[@Image = "entity: Copyright: PMD\n "]
|
||||
+- text[@Image = "\n "]
|
||||
+- child2[]
|
||||
| +- text[@Image = "
|
||||
"]
|
||||
| +- text[@Image = "\n "]
|
||||
| +- cdata-section[@Image = " cdata section "]
|
||||
| +- text[@Image = "
|
||||
"]
|
||||
+- text[@Image = "
|
||||
"]
|
||||
| +- text[@Image = "\n "]
|
||||
+- text[@Image = "\n"]
|
||||
|
@ -1,20 +1,13 @@
|
||||
+- document[]
|
||||
+- pmd:rootElement[@xmlns:pmd = "http://pmd.sf.net"]
|
||||
+- text[@Image = "
|
||||
"]
|
||||
+- text[@Image = "\n "]
|
||||
+- comment[]
|
||||
+- text[@Image = "
|
||||
"]
|
||||
+- text[@Image = "\n "]
|
||||
+- pmd:child1[@test = "1"]
|
||||
| +- text[@Image = "entity: &
|
||||
"]
|
||||
+- text[@Image = "
|
||||
"]
|
||||
| +- text[@Image = "entity: &\n "]
|
||||
+- text[@Image = "\n "]
|
||||
+- pmd:child2[]
|
||||
| +- text[@Image = "
|
||||
"]
|
||||
| +- text[@Image = "\n "]
|
||||
| +- cdata-section[@Image = " cdata section "]
|
||||
| +- text[@Image = "
|
||||
"]
|
||||
+- text[@Image = "
|
||||
"]
|
||||
| +- text[@Image = "\n "]
|
||||
+- text[@Image = "\n"]
|
||||
|
Reference in New Issue
Block a user