From: Dominik Stadler Date: Sun, 3 Jan 2016 13:28:01 +0000 (+0000) Subject: Fix bug 58067: XWPF: don't return deleted text when document is in review-mode X-Git-Tag: REL_3_14_FINAL~101 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=cb441adcb408b57df10194242dfd8151b6cf88df;p=poi.git Fix bug 58067: XWPF: don't return deleted text when document is in review-mode git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1722715 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java index a81ab3b1e8..57ff6bcea6 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java @@ -215,7 +215,13 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para public String getText() { StringBuffer out = new StringBuffer(); for (IRunElement run : iruns) { - if (run instanceof XWPFSDT) { + if (run instanceof XWPFRun) { + XWPFRun xRun = (XWPFRun) run; + // don't include the text if reviewing is enabled and this is a deleted run + if (!xRun.getCTR().isSetRsidDel()) { + out.append(xRun.toString()); + } + } else if (run instanceof XWPFSDT) { out.append(((XWPFSDT) run).getContent().getText()); } else { out.append(run.toString()); diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java index d9fede9b2c..b877451aa8 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java @@ -584,4 +584,15 @@ public final class TestXWPFParagraph { assertNull(p.getRun(null)); doc.close(); } + + @Test + public void test58067() throws IOException { + XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("58067.docx"); + + StringBuilder str = new StringBuilder(); + for(XWPFParagraph par : doc.getParagraphs()) { + str.append(par.getText()).append("\n"); + } + assertEquals("This is a test.\n\n\n\n3\n4\n5\n\n\n\nThis is a whole paragraph where one word is deleted.\n", str.toString()); + } } diff --git a/test-data/document/58067.docx b/test-data/document/58067.docx new file mode 100644 index 0000000000..ede9abbe5b Binary files /dev/null and b/test-data/document/58067.docx differ