]> source.dussan.org Git - poi.git/commitdiff
Fix bug 61787, which was introduced by bug 58067: Change how deleted content is detec...
authorDominik Stadler <centic@apache.org>
Thu, 28 Dec 2017 08:45:51 +0000 (08:45 +0000)
committerDominik Stadler <centic@apache.org>
Thu, 28 Dec 2017 08:45:51 +0000 (08:45 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1819405 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java
src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java
test-data/document/61787.docx [new file with mode: 0644]

index 989c93db5fc7e6b25d01c1308cd29c6c681cc35c..2e7e8238d4b5761f613c9120c8e3b75802470d91 100644 (file)
@@ -148,6 +148,12 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
                 // This implementation does not preserve the tagging information
                 buildRunsInOrderFromXml(o);
             }
+            if (o instanceof CTRunTrackChange) {
+                // add all the insertions as text
+                for (CTRunTrackChange change : ((CTRunTrackChange) o).getInsArray()) {
+                    buildRunsInOrderFromXml(change);
+                }
+            }
         }
         c.dispose();
     }
@@ -189,7 +195,7 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
             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()) {
+                if (xRun.getCTR().getDelTextArray().length == 0) {
                     out.append(xRun);
                 }
             } else if (run instanceof XWPFSDT) {
index 718c73e70be062251b086857c53ddf4664854722..30d9d7ef29f723375d97bf93b93ef03504218342 100644 (file)
@@ -414,7 +414,9 @@ public final class TestXWPFParagraph {
         //CTMoveBookmarkImpl into ooxml-lite.
         XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Tika-792.docx");
         XWPFParagraph paragraph = doc.getParagraphs().get(0);
-        assertEquals("s", paragraph.getText());
+        assertEquals("", paragraph.getText());
+        paragraph = doc.getParagraphs().get(1);
+        assertEquals("b", paragraph.getText());
         doc.close();
     }
 
@@ -612,7 +614,19 @@ public final class TestXWPFParagraph {
         }
         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());
     }
-    
+
+    @Test
+    public void test61787() throws IOException {
+        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("61787.docx");
+
+        StringBuilder str = new StringBuilder();
+        for(XWPFParagraph par : doc.getParagraphs()) {
+            str.append(par.getText()).append("\n");
+        }
+        String s = str.toString();
+        assertTrue("Having text: \n" + s + "\nTrimmed lenght: " + s.trim().length(), s.trim().length() > 0);
+    }
+
     /**
      * Tests for numbered lists
      * 
diff --git a/test-data/document/61787.docx b/test-data/document/61787.docx
new file mode 100644 (file)
index 0000000..0c4c935
Binary files /dev/null and b/test-data/document/61787.docx differ