mirror of https://github.com/apache/poi.git
Fix bug #49936 - Handle HWPF documents with problematic HeaderStories better
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@998146 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8cd8659010
commit
3ed873b593
|
@ -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>
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -21,6 +21,7 @@ import org.apache.poi.EncryptedDocumentException;
|
|||
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 HWPFTestCase {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue