poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r998146 - in /poi/trunk: src/documentation/content/xdocs/ src/scratchpad/src/org/apache/poi/hwpf/usermodel/ src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/ test-data/document/
Date Fri, 17 Sep 2010 14:14:19 GMT
Author: nick
Date: Fri Sep 17 14:14:19 2010
New Revision: 998146

URL: http://svn.apache.org/viewvc?rev=998146&view=rev
Log:
Fix bug #49936 - Handle HWPF documents with problematic HeaderStories better

Added:
    poi/trunk/test-data/document/HeaderFooterProblematic.doc   (with props)
Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/HeaderStories.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestProblems.java

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=998146&r1=998145&r2=998146&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Fri Sep 17 14:14:19 2010
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.7-beta3" date="2010-??-??">
+           <action dev="poi-developers" type="fix">49936 - Handle HWPF documents with
problematic HeaderStories better</action>
            <action dev="poi-developers" type="fix">49933 - Support sections in Word
6 and Word 95 files (HWPFOldDocument)</action>
            <action dev="poi-developers" type="fix">49941 - Correctly handle space preservation
of XSSFRichTextRuns when applying fonts to parts of the string</action>
            <action dev="poi-developers" type="fix">Correct XWPFRun detection of bold/italic
in a paragraph with multiple runs of different styles</action>

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/HeaderStories.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/HeaderStories.java?rev=998146&r1=998145&r2=998146&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/HeaderStories.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/usermodel/HeaderStories.java Fri Sep
17 14:14:19 2010
@@ -157,10 +157,18 @@ public final class HeaderStories {
 			// Empty story
 			return "";
 		}
+		if(prop.getEnd() < prop.getStart()) {
+		   // Broken properties?
+		   return "";
+		}
+
+		// Ensure we're getting a sensible length
+		String rawText = headerStories.text();
+		int start = Math.min(prop.getStart(), rawText.length());
+		int end = Math.min(prop.getEnd(), rawText.length());
 
 		// Grab the contents
-		String text =
-			headerStories.text().substring(prop.getStart(), prop.getEnd());
+		String text = rawText.substring(start, end);
 
 		// Strip off fields and macros if requested
 		if(stripFields) {

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestProblems.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestProblems.java?rev=998146&r1=998145&r2=998146&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestProblems.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestProblems.java Fri
Sep 17 14:14:19 2010
@@ -21,6 +21,7 @@ import org.apache.poi.EncryptedDocumentE
 import org.apache.poi.hwpf.HWPFDocument;
 import org.apache.poi.hwpf.HWPFTestCase;
 import org.apache.poi.hwpf.HWPFTestDataSamples;
+import org.apache.poi.hwpf.extractor.WordExtractor;
 import org.apache.poi.hwpf.model.StyleSheet;
 
 /**
@@ -232,6 +233,27 @@ public final class TestProblems extends 
          }
       }
    }
+   
+   /**
+    * Bug #49936 - Problems with reading the header out of
+    *  the Header Stories
+    */
+   public void testProblemHeaderStories49936() throws Exception {
+      HWPFDocument doc = HWPFTestDataSamples.openSampleFile("HeaderFooterProblematic.doc");
+      HeaderStories hs = new HeaderStories(doc);
+      
+      assertEquals("", hs.getFirstHeader());
+      assertEquals("\r", hs.getEvenHeader());
+      assertEquals("", hs.getOddHeader());
+      
+      assertEquals("", hs.getFirstFooter());
+      assertEquals("", hs.getEvenFooter());
+      assertEquals("", hs.getOddFooter());
+      
+      WordExtractor ext = new WordExtractor(doc);
+      assertEquals("\n", ext.getHeaderText());
+      assertEquals("", ext.getFooterText());
+   }
 
    /**
     * Bug #48245 - don't include the text from the

Added: poi/trunk/test-data/document/HeaderFooterProblematic.doc
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/document/HeaderFooterProblematic.doc?rev=998146&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/document/HeaderFooterProblematic.doc
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message