You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by fa...@apache.org on 2021/09/07 20:08:55 UTC
svn commit: r1893071 -
/xmlbeans/trunk/src/test/java/dom/checkin/ParserTest.java
Author: fanningpj
Date: Tue Sep 7 20:08:55 2021
New Revision: 1893071
URL: http://svn.apache.org/viewvc?rev=1893071&view=rev
Log:
extend ParserTests
Modified:
xmlbeans/trunk/src/test/java/dom/checkin/ParserTest.java
Modified: xmlbeans/trunk/src/test/java/dom/checkin/ParserTest.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/dom/checkin/ParserTest.java?rev=1893071&r1=1893070&r2=1893071&view=diff
==============================================================================
--- xmlbeans/trunk/src/test/java/dom/checkin/ParserTest.java (original)
+++ xmlbeans/trunk/src/test/java/dom/checkin/ParserTest.java Tue Sep 7 20:08:55 2021
@@ -17,15 +17,18 @@
package dom.checkin;
import org.apache.xmlbeans.XmlOptions;
+import org.apache.xmlbeans.impl.common.DocumentHelper;
import org.apache.xmlbeans.impl.common.SAXHelper;
import org.apache.xmlbeans.impl.common.StaxHelper;
import org.apache.xmlbeans.impl.common.XMLBeansConstants;
import org.junit.Test;
import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
-import javax.xml.stream.XMLInputFactory;
import java.io.ByteArrayInputStream;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.stream.XMLInputFactory;
import static org.junit.Assert.*;
@@ -89,10 +92,11 @@ public class ParserTest {
assertEquals(SAXHelper.IGNORING_ENTITY_RESOLVER, reader.getEntityResolver());
assertNotNull(reader.getProperty(XMLBeansConstants.SECURITY_MANAGER));
- reader.parse(new InputSource(new ByteArrayInputStream("<xml></xml>".getBytes("UTF-8"))));
+ String xmlWithDtd = "<!DOCTYPE foo [<!ELEMENT t ANY><!ENTITY xe \"TEST XXE\"> ]>\n<xml>&xe;</xml>";
+ reader.parse(new InputSource(new ByteArrayInputStream(xmlWithDtd.getBytes("UTF-8"))));
}
- @Test
+ @Test(expected = SAXException.class)
public void testXMLReaderOverrides() throws Exception {
XmlOptions options = new XmlOptions();
options.setEntityExpansionLimit(1);
@@ -107,6 +111,31 @@ public class ParserTest {
assertEquals(SAXHelper.IGNORING_ENTITY_RESOLVER, reader.getEntityResolver());
assertNotNull(reader.getProperty(XMLBeansConstants.SECURITY_MANAGER));
- reader.parse(new InputSource(new ByteArrayInputStream("<xml></xml>".getBytes("UTF-8"))));
+ String xmlWithDtd = "<!DOCTYPE foo [<!ELEMENT t ANY><!ENTITY xe \"TEST XXE\"> ]>\n<xml>&xe;</xml>";
+ reader.parse(new InputSource(new ByteArrayInputStream(xmlWithDtd.getBytes("UTF-8"))));
+ }
+
+ @Test
+ public void testDocumentBuilder() throws Exception {
+ XmlOptions options = new XmlOptions();
+ DocumentBuilder builder = DocumentHelper.newDocumentBuilder(options);
+ assertNotSame(builder, DocumentHelper.newDocumentBuilder(options));
+
+ String xmlWithDtd = "<!DOCTYPE foo [<!ELEMENT t ANY><!ENTITY xe \"TEST XXE\"> ]>\n<xml>&xe;</xml>";
+ builder.parse(new InputSource(new ByteArrayInputStream(xmlWithDtd.getBytes("UTF-8"))));
+ }
+
+ @Test(expected = SAXException.class)
+ public void testDocumentBuilderOverrides() throws Exception {
+ XmlOptions options = new XmlOptions();
+ options.setEntityExpansionLimit(1);
+ options.setLoadDTDGrammar(true);
+ options.setLoadExternalDTD(true);
+ options.setDisallowDocTypeDeclaration(true);
+ DocumentBuilder builder = DocumentHelper.newDocumentBuilder(options);
+ assertNotSame(builder, DocumentHelper.newDocumentBuilder(options));
+
+ String xmlWithDtd = "<!DOCTYPE foo [<!ELEMENT t ANY><!ENTITY xe \"TEST XXE\"> ]>\n<xml>&xe;</xml>";
+ builder.parse(new InputSource(new ByteArrayInputStream(xmlWithDtd.getBytes("UTF-8"))));
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org