mirror of https://github.com/apache/poi.git
[bug-65706] ignore trash parts in OOXML files
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1895370 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b5d1b91780
commit
7475b1f609
|
@ -330,14 +330,17 @@ public final class ZipPackage extends OPCPackage {
|
|||
|
||||
final String entryName = zipArchiveEntry.getName();
|
||||
PackagePartName ppn = null;
|
||||
try {
|
||||
// We get an error when we parse [Content_Types].xml
|
||||
// because it's not a valid URI.
|
||||
ppn = (CONTENT_TYPES_PART_NAME.equalsIgnoreCase(entryName)) ? null
|
||||
: PackagingURIHelper.createPartName(ZipHelper.getOPCNameFromZipItemName(entryName));
|
||||
} catch (Exception e) {
|
||||
// We assume we can continue, even in degraded mode ...
|
||||
LOG.atWarn().withThrowable(e).log("Entry {} is not valid, so this part won't be added to the package.", entryName);
|
||||
// ignore trash parts
|
||||
if (!entryName.startsWith("[trash]")) {
|
||||
try {
|
||||
// We get an error when we parse [Content_Types].xml
|
||||
// because it's not a valid URI.
|
||||
ppn = (CONTENT_TYPES_PART_NAME.equalsIgnoreCase(entryName)) ? null
|
||||
: PackagingURIHelper.createPartName(ZipHelper.getOPCNameFromZipItemName(entryName));
|
||||
} catch (Exception e) {
|
||||
// We assume we can continue, even in degraded mode ...
|
||||
LOG.atWarn().withThrowable(e).log("Entry {} is not valid, so this part won't be added to the package.", entryName);
|
||||
}
|
||||
}
|
||||
|
||||
this.partName = ppn;
|
||||
|
|
|
@ -1289,6 +1289,16 @@ public final class TestXSSFWorkbook extends BaseTestXWorkbook {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testIgnoreTrashParts() throws Exception {
|
||||
try (XSSFWorkbook workbook = openSampleWorkbook("Excel_file_with_trash_item.xlsx")) {
|
||||
for (PackagePart packagePart : workbook.getPackage().getParts()) {
|
||||
assertFalse(packagePart.getPartName().toString().contains("trash"),
|
||||
"should ignore part " + packagePart.getPartName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void expectFormattedContent(Cell cell, String value) {
|
||||
assertEquals(value, new DataFormatter().formatCellValue(cell),
|
||||
"Cell " + ref(cell) + " has wrong formatted content.");
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue