diff --git a/src/main/java/com/adobe/epubcheck/ocf/OCFChecker.java b/src/main/java/com/adobe/epubcheck/ocf/OCFChecker.java index 5680a9e58..29fd03960 100755 --- a/src/main/java/com/adobe/epubcheck/ocf/OCFChecker.java +++ b/src/main/java/com/adobe/epubcheck/ocf/OCFChecker.java @@ -307,9 +307,11 @@ else if (validationVersion == EPUBVersion.VERSION_3) // try { + // report duplicate entries Set entriesSet = new HashSet(); Set normalizedEntriesSet = new HashSet(); - for (final String entry : ocf.getFileEntries()) + // run duplicate check from the LinkedList which may contain duplicates + for (final String entry : ocf.getEntries()) { if (!entriesSet.add(entry.toLowerCase(Locale.ENGLISH))) { @@ -319,7 +321,11 @@ else if (!normalizedEntriesSet.add(Normalizer.normalize(entry, Form.NFC))) { report.message(MessageId.OPF_061, EPUBLocation.create(ocf.getPackagePath()), entry); } + } + // check all file entries without duplicates + for (final String entry : ocf.getFileEntries()) + { ocf.reportMetadata(entry, report); // if the entry is not in the whitelist (META-INF/* + mimetype) @@ -345,6 +351,7 @@ public boolean apply(OPFHandler opfHandler) OCFFilenameChecker.checkCompatiblyEscaped(entry, report, validationVersion); } + // check all directory entries without duplicates for (String directory : ocf.getDirectoryEntries()) { boolean hasContents = false; diff --git a/src/main/java/com/adobe/epubcheck/ocf/OCFPackage.java b/src/main/java/com/adobe/epubcheck/ocf/OCFPackage.java index 2b809c2cf..6ee0b189b 100644 --- a/src/main/java/com/adobe/epubcheck/ocf/OCFPackage.java +++ b/src/main/java/com/adobe/epubcheck/ocf/OCFPackage.java @@ -107,14 +107,14 @@ public abstract List getEntries() throws IOException; /** - * @return a set of relative file names of files in this container + * @return a set of relative file names of files in this container (cleaned from duplicates) * @throws IOException */ public abstract Set getFileEntries() throws IOException; /** - * @return a set of relative directory entries in this container + * @return a set of relative directory entries in this container (cleaned from duplicates) * @throws IOException */ public abstract Set getDirectoryEntries() diff --git a/src/main/java/com/adobe/epubcheck/ocf/OCFZipPackage.java b/src/main/java/com/adobe/epubcheck/ocf/OCFZipPackage.java index 18b609ecf..591d2a488 100644 --- a/src/main/java/com/adobe/epubcheck/ocf/OCFZipPackage.java +++ b/src/main/java/com/adobe/epubcheck/ocf/OCFZipPackage.java @@ -6,7 +6,6 @@ import java.security.MessageDigest; import java.util.Collections; import java.util.Enumeration; -import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Set; @@ -150,16 +149,14 @@ public Set getFileEntries() throws public Set getDirectoryEntries() throws IOException { - HashSet entryNames = new HashSet(); - for (Enumeration entries = zip.entries(); entries.hasMoreElements(); ) + synchronized (zip) { - ZipEntry entry = entries.nextElement(); - if (entry.isDirectory()) + if (allEntries == null) { - entryNames.add(entry.getName()); + listEntries(); } + return Collections.unmodifiableSet(dirEntries); } - return entryNames; } public void reportMetadata(String fileName, Report report) diff --git a/src/test/java/com/adobe/epubcheck/api/Epub30CheckTest.java b/src/test/java/com/adobe/epubcheck/api/Epub30CheckTest.java index 7cf1a548b..d8340dd4d 100644 --- a/src/test/java/com/adobe/epubcheck/api/Epub30CheckTest.java +++ b/src/test/java/com/adobe/epubcheck/api/Epub30CheckTest.java @@ -208,13 +208,14 @@ public void testFilenameContainsSpacesIssue239() public void testDuplicateZipEntriesIssue265() { // duplicate entries should raise an error + Collections.addAll(expectedErrors, MessageId.OPF_060); testValidateDocument("invalid/issue265.epub"); } @Test public void testDuplicateZipEntriesIssue265b() { - Collections.addAll(expectedWarnings, MessageId.OPF_003, MessageId.PKG_012, MessageId.OPF_061, + Collections.addAll(expectedWarnings, MessageId.OPF_061, MessageId.OPF_003, MessageId.PKG_012, MessageId.PKG_012); // non-unique entry names (after NFC normalization) should raise a warning testValidateDocument("invalid/issue265b.epub");