diff options
4 files changed, 31 insertions, 19 deletions
diff --git a/build.gradle b/build.gradle index a1eb2d95f8..95a9f62c3a 100644 --- a/build.gradle +++ b/build.gradle @@ -24,7 +24,7 @@ import javax.xml.xpath.XPathFactory buildscript { repositories { - maven { url 'https://plugins.gradle.org/m2/' } + maven { url = 'https://plugins.gradle.org/m2/' } mavenCentral() } } diff --git a/poi-ooxml/src/main/java/org/apache/poi/ooxml/POIXMLTypeLoader.java b/poi-ooxml/src/main/java/org/apache/poi/ooxml/POIXMLTypeLoader.java index e848e383cd..5a4ca30c49 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/ooxml/POIXMLTypeLoader.java +++ b/poi-ooxml/src/main/java/org/apache/poi/ooxml/POIXMLTypeLoader.java @@ -43,6 +43,9 @@ public class POIXMLTypeLoader { DEFAULT_XML_OPTIONS.setCharacterEncoding("UTF-8"); DEFAULT_XML_OPTIONS.setDisallowDocTypeDeclaration(true); DEFAULT_XML_OPTIONS.setEntityExpansionLimit(1); + DEFAULT_XML_OPTIONS.setLoadStripProcinsts(true); + DEFAULT_XML_OPTIONS.setLoadStripComments(true); + // JAXP is used for parsing // so only user code using XmlObject/XmlToken.Factory.parse // directly can bypass the entity check, which is probably unlikely (... and not within our responsibility :)) diff --git a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFTable.java b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFTable.java index dc4d0e4116..c9fe1cdd1e 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFTable.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFTable.java @@ -314,7 +314,7 @@ public class XWPFTable implements IBodyElement, ISDTContents { * edge in a right-to-left table).</p> * <p>If the table alignment is not left/start, this property shall be ignored.</p> * - * @see boolean hasIndent() + * @see #hasIndent() * @return indentation value as an integer (20ths of a point) */ public int getIndent() { @@ -343,7 +343,7 @@ public class XWPFTable implements IBodyElement, ISDTContents { /** * Set the indentation in 20ths of a point (twips). - * @see int getIndent() + * @see #getIndent() * @param indent Indentation value (20ths of a point) */ public void setIndent(int indent) { diff --git a/poi-ooxml/src/test/java/org/apache/poi/xwpf/TestXWPFBugs.java b/poi-ooxml/src/test/java/org/apache/poi/xwpf/TestXWPFBugs.java index 170473396e..5611064220 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xwpf/TestXWPFBugs.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xwpf/TestXWPFBugs.java @@ -29,6 +29,7 @@ import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; import org.apache.commons.compress.archivers.zip.ZipFile; import org.apache.poi.POIDataSamples; import org.apache.poi.POIException; +import org.apache.poi.ooxml.POIXMLException; import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackagePartName; @@ -137,11 +138,11 @@ class TestXWPFBugs { void bug59058() throws IOException, XmlException { String[] files = {"bug57031.docx", "bug59058.docx"}; for (String f : files) { - ZipFile zf = new ZipFile(samples.getFile(f)); - ZipArchiveEntry entry = zf.getEntry("word/document.xml"); - DocumentDocument document = DocumentDocument.Factory.parse(zf.getInputStream(entry)); - assertNotNull(document); - zf.close(); + try (ZipFile zf = ZipFile.builder().setFile(samples.getFile(f)).get()) { + ZipArchiveEntry entry = zf.getEntry("word/document.xml"); + DocumentDocument document = DocumentDocument.Factory.parse(zf.getInputStream(entry)); + assertNotNull(document); + } } } @@ -149,11 +150,11 @@ class TestXWPFBugs { void missingXsbs() throws IOException, XmlException { String[] files = {"bib-chernigovka.netdo.ru_download_docs_17459.docx"}; for (String f : files) { - ZipFile zf = new ZipFile(samples.getFile(f)); - ZipArchiveEntry entry = zf.getEntry("word/document.xml"); - DocumentDocument document = DocumentDocument.Factory.parse(zf.getInputStream(entry)); - assertNotNull(document); - zf.close(); + try (ZipFile zf = ZipFile.builder().setFile(samples.getFile(f)).get()) { + ZipArchiveEntry entry = zf.getEntry("word/document.xml"); + DocumentDocument document = DocumentDocument.Factory.parse(zf.getInputStream(entry)); + assertNotNull(document); + } } } @@ -277,11 +278,19 @@ class TestXWPFBugs { } @Test - public void testDeepTableCell() throws Exception { - // Document contains a table with nested cells. - IOException ex = assertThrows(IOException.class, - () -> XWPFTestDataSamples.openSampleDocument("deep-table-cell.docx")); - assertInstanceOf(POIException.class, ex.getCause()); - assertTrue(ex.getMessage().contains("Node depth exceeds maximum supported depth")); + public void testDeepTableCell() { + try { + // Document contains a table with nested cells. + //noinspection resource + XWPFTestDataSamples.openSampleDocument("deep-table-cell.docx"); + fail("Should catch exception"); + } catch (POIXMLException e) { + // JDK 25+ does more checks, so more than one exception are possible + assertTrue(e.getMessage().contains("The element \"w:t\" has a depth"), + "Had: " + e); + } catch (IOException e) { + assertInstanceOf(POIException.class, e.getCause()); + assertTrue(e.getMessage().contains("Node depth exceeds maximum supported depth")); + } } } |