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
c07e529c03
commit
100095bcb9
@ -34,6 +34,7 @@
|
|||||||
|
|
||||||
<changes>
|
<changes>
|
||||||
<release version="3.7-beta3" date="2010-??-??">
|
<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">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">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>
|
<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
|
// Empty story
|
||||||
return "";
|
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
|
// Grab the contents
|
||||||
String text =
|
String text = rawText.substring(start, end);
|
||||||
headerStories.text().substring(prop.getStart(), prop.getEnd());
|
|
||||||
|
|
||||||
// Strip off fields and macros if requested
|
// Strip off fields and macros if requested
|
||||||
if(stripFields) {
|
if(stripFields) {
|
||||||
|
@ -21,6 +21,7 @@ import org.apache.poi.EncryptedDocumentException;
|
|||||||
import org.apache.poi.hwpf.HWPFDocument;
|
import org.apache.poi.hwpf.HWPFDocument;
|
||||||
import org.apache.poi.hwpf.HWPFTestCase;
|
import org.apache.poi.hwpf.HWPFTestCase;
|
||||||
import org.apache.poi.hwpf.HWPFTestDataSamples;
|
import org.apache.poi.hwpf.HWPFTestDataSamples;
|
||||||
|
import org.apache.poi.hwpf.extractor.WordExtractor;
|
||||||
import org.apache.poi.hwpf.model.StyleSheet;
|
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
|
* Bug #48245 - don't include the text from the
|
||||||
|
BIN
test-data/document/HeaderFooterProblematic.doc
Normal file
BIN
test-data/document/HeaderFooterProblematic.doc
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user