aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominik Stadler <centic@apache.org>2021-01-30 18:42:14 +0000
committerDominik Stadler <centic@apache.org>2021-01-30 18:42:14 +0000
commitcaf2d32393f6179673a615e9f0db5ef06956654e (patch)
tree2e22ae9fcb2618e08b16799a900edb3549bebaf6
parent6449c03a531eed581d93882c88e2ad317f4a05cd (diff)
downloadpoi-caf2d32393f6179673a615e9f0db5ef06956654e.tar.gz
poi-caf2d32393f6179673a615e9f0db5ef06956654e.zip
Bug 65099: Fix incorrect handling of styles in XWPFStyle.getUsedStyleList
Closes github #216 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1886063 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java4
-rw-r--r--src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java31
-rw-r--r--src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFStyles.java6
-rw-r--r--test-data/document/65099.docxbin0 -> 17126 bytes
4 files changed, 36 insertions, 5 deletions
diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java
index 3d4b1b7268..93b05ab901 100644
--- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java
+++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java
@@ -228,8 +228,8 @@ public class XWPFStyles extends POIXMLDocumentPart {
String nextStyleID = style.getNextStyleID();
XWPFStyle nextStyle = getStyle(nextStyleID);
if ((nextStyle != null) && (!usedStyleList.contains(nextStyle))) {
- usedStyleList.add(linkStyle);
- getUsedStyleList(linkStyle, usedStyleList);
+ usedStyleList.add(nextStyle);
+ getUsedStyleList(nextStyle, usedStyleList);
}
return usedStyleList;
}
diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java
index 4ad0d80a8c..2974c879dc 100644
--- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java
+++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java
@@ -20,12 +20,14 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.math.BigInteger;
+import java.util.List;
import org.apache.poi.util.Units;
import org.apache.poi.xwpf.XWPFTestDataSamples;
@@ -230,4 +232,33 @@ class TestXWPFBugs {
documentNumbering.addNum(abstractNumID);
}
+
+ @Test
+ public void test65099() throws IOException {
+ try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("65099.docx")) {
+ XWPFStyles styles = doc.getStyles();
+ assertNotNull(styles);
+
+ XWPFStyle normal = styles.getStyle("Normal");
+ assertNotNull(normal);
+
+ XWPFStyle style1 = styles.getStyle("EdfTitre3Car");
+ assertNotNull(style1);
+
+ List<XWPFStyle> list = styles.getUsedStyleList(normal);
+ assertNotNull(list);
+ assertEquals(1, list.size());
+
+ list = styles.getUsedStyleList(style1);
+ assertNotNull(list);
+ assertEquals(7, list.size());
+
+ assertThrows(NullPointerException.class,
+ () -> styles.getUsedStyleList(null),
+ "Pasisng in 'null' triggers an exception");
+
+ XWPFStyle style = doc.getStyles().getStyle("TableauGrille41");
+ doc.getStyles().getUsedStyleList(style);
+ }
+ }
}
diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFStyles.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFStyles.java
index fcabe249dd..6c517f4c95 100644
--- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFStyles.java
+++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFStyles.java
@@ -170,7 +170,7 @@ public final class TestXWPFStyles {
assertNull(r.getColor());
assertNull(r.getFontFamily());
assertNull(r.getFontName());
- assertEquals(-1, r.getFontSize());
+ assertNull(r.getFontSizeAsDouble());
}
// On page two, has explicit styles, but on runs not on
@@ -184,7 +184,7 @@ public final class TestXWPFStyles {
XWPFRun r = p.getRuns().get(0);
assertEquals("Arial Black", r.getFontFamily());
assertEquals("Arial Black", r.getFontName());
- assertEquals(16, r.getFontSize());
+ assertEquals(16.0, r.getFontSizeAsDouble(), 0.01);
assertEquals("548DD4", r.getColor());
}
@@ -203,7 +203,7 @@ public final class TestXWPFStyles {
assertNotNull(styles.getDefaultRunStyle());
assertNotNull(styles.getDefaultParagraphStyle());
- assertEquals(11, styles.getDefaultRunStyle().getFontSize());
+ assertEquals(11.0, styles.getDefaultRunStyle().getFontSizeAsDouble(), 0.01);
assertEquals(11.0, styles.getDefaultRunStyle().getFontSizeAsDouble(), 0.01);
assertEquals(200, styles.getDefaultParagraphStyle().getSpacingAfter());
}
diff --git a/test-data/document/65099.docx b/test-data/document/65099.docx
new file mode 100644
index 0000000000..a0b57db943
--- /dev/null
+++ b/test-data/document/65099.docx
Binary files differ