Skip to content

Commit

Permalink
add dc:identifier UUID validation // fixes #853
Browse files Browse the repository at this point in the history
  • Loading branch information
tofi86 authored and rdeltour committed Nov 20, 2018
1 parent e7dfedd commit 48800a0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ static Map<MessageId, Severity> getDefaultSeverities()
map.put(MessageId.OPF_082, Severity.ERROR);
map.put(MessageId.OPF_083, Severity.ERROR);
map.put(MessageId.OPF_084, Severity.ERROR);
map.put(MessageId.OPF_085, Severity.ERROR);

// PKG
map.put(MessageId.PKG_001, Severity.WARNING);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/adobe/epubcheck/messages/MessageId.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ public enum MessageId implements Comparable<MessageId>
OPF_082("OPF-082"),
OPF_083("OPF-083"),
OPF_084("OPF-084"),
OPF_085("OPF-085"),

// Messages relating to the entire package
PKG_001("PKG-001"),
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/adobe/epubcheck/opf/OPFHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.Vector;

import com.adobe.epubcheck.api.EPUBLocation;
Expand Down Expand Up @@ -507,6 +508,18 @@ else if (e.getNamespace().equals("http://purl.org/dc/elements/1.1/"))
if (idval != null)
{
report.info(null, FeatureEnum.UNIQUE_IDENT, idval.trim());

uid = idval.trim();

// #853
String opfSchemeAttr = e.getAttributeNS("http://www.idpf.org/2007/opf", "scheme");
if(uid.startsWith("urn:uuid:") || (opfSchemeAttr != null && opfSchemeAttr.toLowerCase().equals("uuid"))) {
try {
UUID.fromString(uid.replaceAll("urn:uuid:", ""));
} catch (Throwable t) {
report.message(MessageId.OPF_085, EPUBLocation.create(path, parser.getLineNumber(), parser.getColumnNumber()), uid);
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ OPF_081=Resource '%1$s' (referenced from an EPUB Dictionary collection) was not
OPF_082=Found an EPUB Dictionary collection containing more than one Search Key Map Document.
OPF_083=Found an EPUB Dictionary collection containing no Search Key Map Document.
OPF_084=Found an EPUB Dictionary collection containing resource '%1$s' which is neither a Search Key Map Document nor an XHTML Content Document.
OPF_085='dc:identifier' value '%1$s' is marked as a UUID, but is an invalid UUID. The UUID muste be composed by 5 dash-separated parts.

#Package
PKG_001=Validating the EPUB against version %1$s but detected version %2$s.
Expand Down

0 comments on commit 48800a0

Please sign in to comment.