Fix bug #54506 - Add "BOOK" to the list of unusual-but-largely-ok Workbook directory entry names list, alongside WORKBOOK, plus tests
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1443745 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
887af17af3
commit
8d7d3f54c0
@ -193,7 +193,8 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
|
|||||||
*/
|
*/
|
||||||
private static final String[] WORKBOOK_DIR_ENTRY_NAMES = {
|
private static final String[] WORKBOOK_DIR_ENTRY_NAMES = {
|
||||||
"Workbook", // as per BIFF8 spec
|
"Workbook", // as per BIFF8 spec
|
||||||
"WORKBOOK",
|
"WORKBOOK", // Typically from third party programs
|
||||||
|
"BOOK", // Typically odd Crystal Reports exports
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -1180,9 +1181,11 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
|
|||||||
if (preserveNodes) {
|
if (preserveNodes) {
|
||||||
// Don't write out the old Workbook, we'll be doing our new one
|
// Don't write out the old Workbook, we'll be doing our new one
|
||||||
excepts.add("Workbook");
|
excepts.add("Workbook");
|
||||||
// If the file had WORKBOOK instead of Workbook, we'll write it
|
// If the file had an "incorrect" name for the workbook stream,
|
||||||
// out correctly shortly, so don't include the old one
|
// don't write the old one as we'll use the correct name shortly
|
||||||
excepts.add("WORKBOOK");
|
for (String wrongName : WORKBOOK_DIR_ENTRY_NAMES) {
|
||||||
|
excepts.add(wrongName);
|
||||||
|
}
|
||||||
|
|
||||||
// Copy over all the other nodes to our new poifs
|
// Copy over all the other nodes to our new poifs
|
||||||
copyNodes(this.directory, fs.getRoot(), excepts);
|
copyNodes(this.directory, fs.getRoot(), excepts);
|
||||||
|
@ -75,7 +75,7 @@ public class AllUserModelTests {
|
|||||||
result.addTestSuite(TestUnfixedBugs.class);
|
result.addTestSuite(TestUnfixedBugs.class);
|
||||||
}
|
}
|
||||||
result.addTestSuite(TestUnicodeWorkbook.class);
|
result.addTestSuite(TestUnicodeWorkbook.class);
|
||||||
result.addTestSuite(TestUppercaseWorkbook.class);
|
result.addTestSuite(TestNonStandardWorkbookStreamNames.class);
|
||||||
result.addTestSuite(TestWorkbook.class);
|
result.addTestSuite(TestWorkbook.class);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -29,17 +29,17 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for how HSSFWorkbook behaves with XLS files
|
* Tests for how HSSFWorkbook behaves with XLS files
|
||||||
* with a WORKBOOK directory entry (instead of the more
|
* with a WORKBOOK or BOOK directory entry (instead of
|
||||||
* usual, Workbook)
|
* the more usual, Workbook)
|
||||||
*/
|
*/
|
||||||
public final class TestUppercaseWorkbook extends TestCase {
|
public final class TestNonStandardWorkbookStreamNames extends TestCase {
|
||||||
|
|
||||||
private String xlsA = "WORKBOOK_in_capitals.xls";
|
private String xlsA = "WORKBOOK_in_capitals.xls";
|
||||||
|
private String xlsB = "BOOK_in_capitals.xls";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that we can open a file with WORKBOOK
|
* Test that we can open a file with WORKBOOK
|
||||||
*/
|
*/
|
||||||
public void testOpen() throws Exception {
|
public void testOpenWORKBOOK() throws Exception {
|
||||||
InputStream is = HSSFTestDataSamples.openSampleFileStream(xlsA);
|
InputStream is = HSSFTestDataSamples.openSampleFileStream(xlsA);
|
||||||
|
|
||||||
POIFSFileSystem fs = new POIFSFileSystem(is);
|
POIFSFileSystem fs = new POIFSFileSystem(is);
|
||||||
@ -60,11 +60,39 @@ public final class TestUppercaseWorkbook extends TestCase {
|
|||||||
HSSFWorkbook wb = new HSSFWorkbook(fs);
|
HSSFWorkbook wb = new HSSFWorkbook(fs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that we can open a file with BOOK
|
||||||
|
*/
|
||||||
|
public void testOpenBOOK() throws Exception {
|
||||||
|
InputStream is = HSSFTestDataSamples.openSampleFileStream(xlsB);
|
||||||
|
|
||||||
|
POIFSFileSystem fs = new POIFSFileSystem(is);
|
||||||
|
|
||||||
|
// Ensure that we have a BOOK entry
|
||||||
|
fs.getRoot().getEntry("BOOK");
|
||||||
|
assertTrue(true);
|
||||||
|
|
||||||
|
// But not a Workbook one
|
||||||
|
try {
|
||||||
|
fs.getRoot().getEntry("Workbook");
|
||||||
|
fail();
|
||||||
|
} catch(FileNotFoundException e) {}
|
||||||
|
// And not a Summary one
|
||||||
|
try {
|
||||||
|
fs.getRoot().getEntry("\005SummaryInformation");
|
||||||
|
fail();
|
||||||
|
} catch(FileNotFoundException e) {}
|
||||||
|
|
||||||
|
// Try to open the workbook
|
||||||
|
HSSFWorkbook wb = new HSSFWorkbook(fs);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that when we write out, we go back to the correct case
|
* Test that when we write out, we go back to the correct case
|
||||||
*/
|
*/
|
||||||
public void testWrite() throws Exception {
|
public void testWrite() throws Exception {
|
||||||
InputStream is = HSSFTestDataSamples.openSampleFileStream(xlsA);
|
for (String file : new String[] {xlsA, xlsB}) {
|
||||||
|
InputStream is = HSSFTestDataSamples.openSampleFileStream(file);
|
||||||
POIFSFileSystem fs = new POIFSFileSystem(is);
|
POIFSFileSystem fs = new POIFSFileSystem(is);
|
||||||
|
|
||||||
// Open the workbook, not preserving nodes
|
// Open the workbook, not preserving nodes
|
||||||
@ -78,6 +106,10 @@ public final class TestUppercaseWorkbook extends TestCase {
|
|||||||
|
|
||||||
// Check that we have the new entries
|
// Check that we have the new entries
|
||||||
fs2.getRoot().getEntry("Workbook");
|
fs2.getRoot().getEntry("Workbook");
|
||||||
|
try {
|
||||||
|
fs2.getRoot().getEntry("BOOK");
|
||||||
|
fail();
|
||||||
|
} catch(FileNotFoundException e) {}
|
||||||
try {
|
try {
|
||||||
fs2.getRoot().getEntry("WORKBOOK");
|
fs2.getRoot().getEntry("WORKBOOK");
|
||||||
fail();
|
fail();
|
||||||
@ -86,6 +118,7 @@ public final class TestUppercaseWorkbook extends TestCase {
|
|||||||
// And it can be opened
|
// And it can be opened
|
||||||
HSSFWorkbook wb2 = new HSSFWorkbook(fs2);
|
HSSFWorkbook wb2 = new HSSFWorkbook(fs2);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that when we write out preserving nodes, we go back to the
|
* Test that when we write out preserving nodes, we go back to the
|
BIN
test-data/spreadsheet/BOOK_in_capitals.xls
Normal file
BIN
test-data/spreadsheet/BOOK_in_capitals.xls
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user