You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ce...@apache.org on 2021/01/30 18:42:14 UTC
svn commit: r1886063 - in /poi/trunk:
src/ooxml/java/org/apache/poi/xwpf/usermodel/
src/ooxml/testcases/org/apache/poi/xwpf/usermodel/ test-data/document/
Author: centic
Date: Sat Jan 30 18:42:14 2021
New Revision: 1886063
URL: http://svn.apache.org/viewvc?rev=1886063&view=rev
Log:
Bug 65099: Fix incorrect handling of styles in XWPFStyle.getUsedStyleList
Closes github #216
Added:
poi/trunk/test-data/document/65099.docx
Modified:
poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java
poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java
poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFStyles.java
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java?rev=1886063&r1=1886062&r2=1886063&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java Sat Jan 30 18:42:14 2021
@@ -228,8 +228,8 @@ public class XWPFStyles extends POIXMLDo
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;
}
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java?rev=1886063&r1=1886062&r2=1886063&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java Sat Jan 30 18:42:14 2021
@@ -20,12 +20,14 @@ import static org.junit.jupiter.api.Asse
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);
+ }
+ }
}
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFStyles.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFStyles.java?rev=1886063&r1=1886062&r2=1886063&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFStyles.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFStyles.java Sat Jan 30 18:42:14 2021
@@ -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());
}
Added: poi/trunk/test-data/document/65099.docx
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/document/65099.docx?rev=1886063&view=auto
==============================================================================
Binary files poi/trunk/test-data/document/65099.docx (added) and poi/trunk/test-data/document/65099.docx Sat Jan 30 18:42:14 2021 differ
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org