From: PJ Fanning Date: Fri, 10 Dec 2021 18:07:25 +0000 (+0000) Subject: [bug-65738] do not treat zip directories as parts X-Git-Tag: REL_5_2_0~94 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=11b0cf965cdae8f512daa5bb3c2dbd809e05d305;p=poi.git [bug-65738] do not treat zip directories as parts git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1895788 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/ZipPackage.java b/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/ZipPackage.java index 45c1f282e6..8feaf81252 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/ZipPackage.java +++ b/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/ZipPackage.java @@ -308,6 +308,7 @@ public final class ZipPackage extends OPCPackage { // its relationship exists, and then it won't tie up) final List entries = Collections.list(zipArchive.getEntries()).stream() + .filter(zipArchiveEntry -> !ignoreEntry(zipArchiveEntry)) .map(zae -> new EntryTriple(zae, contentTypeManager)) .filter(mm -> mm.partName != null) .sorted() @@ -320,6 +321,11 @@ public final class ZipPackage extends OPCPackage { return newPartList; } + private static boolean ignoreEntry(ZipArchiveEntry zipArchiveEntry) { + String name = zipArchiveEntry.getName(); + return name.startsWith("[trash]") || name.endsWith("/"); + } + private class EntryTriple implements Comparable { final ZipArchiveEntry zipArchiveEntry; final PackagePartName partName; @@ -331,7 +337,7 @@ public final class ZipPackage extends OPCPackage { final String entryName = zipArchiveEntry.getName(); PackagePartName ppn = null; // ignore trash parts - if (!entryName.startsWith("[trash]")) { + if (!ignoreEntry(zipArchiveEntry)) { try { // We get an error when we parse [Content_Types].xml // because it's not a valid URI.