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
This commit is contained in:
Dominik Stadler 2021-01-30 18:42:14 +00:00
parent 6449c03a53
commit caf2d32393
4 changed files with 36 additions and 5 deletions

View File

@ -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;
}

View File

@ -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);
}
}
}

View File

@ -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());
}

Binary file not shown.