diff --git a/src/main/java/com/adobe/epubcheck/messages/DefaultSeverities.java b/src/main/java/com/adobe/epubcheck/messages/DefaultSeverities.java index 78dea852e..438ce5eb7 100644 --- a/src/main/java/com/adobe/epubcheck/messages/DefaultSeverities.java +++ b/src/main/java/com/adobe/epubcheck/messages/DefaultSeverities.java @@ -150,6 +150,7 @@ private void initialize() severities.put(MessageId.MED_011, Severity.ERROR); severities.put(MessageId.MED_012, Severity.ERROR); severities.put(MessageId.MED_013, Severity.ERROR); + severities.put(MessageId.MED_014, Severity.ERROR); // NAV severities.put(MessageId.NAV_001, Severity.ERROR); diff --git a/src/main/java/com/adobe/epubcheck/messages/MessageId.java b/src/main/java/com/adobe/epubcheck/messages/MessageId.java index 41ebb0ee5..a65c56374 100644 --- a/src/main/java/com/adobe/epubcheck/messages/MessageId.java +++ b/src/main/java/com/adobe/epubcheck/messages/MessageId.java @@ -144,6 +144,7 @@ public enum MessageId implements Comparable MED_011("MED_011"), MED_012("MED_012"), MED_013("MED_013"), + MED_014("MED_014"), // Epub3 based table of content errors NAV_001("NAV-001"), diff --git a/src/main/java/com/adobe/epubcheck/overlay/OverlayHandler.java b/src/main/java/com/adobe/epubcheck/overlay/OverlayHandler.java index c5f9f4217..3b86be119 100644 --- a/src/main/java/com/adobe/epubcheck/overlay/OverlayHandler.java +++ b/src/main/java/com/adobe/epubcheck/overlay/OverlayHandler.java @@ -64,29 +64,28 @@ public void startElement() XMLElement e = parser.getCurrentElement(); String name = e.getName(); - if (name.equals("smil")) - { - vocabs = VocabUtil.parsePrefixDeclaration( - e.getAttributeNS(EpubConstants.EpubTypeNamespaceUri, "prefix"), RESERVED_VOCABS, - KNOWN_VOCAB_URIS, DEFAULT_VOCAB_URIS, report, - EPUBLocation.create(path, parser.getLineNumber(), parser.getColumnNumber())); - } - else if (name.equals("seq")) - { - processSeq(e); - } - else if (name.equals("text")) - { - processSrc(e); - } - else if (name.equals("audio")) - { - processRef(e.getAttribute("src"), XRefChecker.Type.AUDIO); - checkTime(e.getAttribute("clipBegin"), e.getAttribute("clipEnd")); - } - else if (name.equals("body") || name.equals("par")) - { - checkType(e.getAttributeNS(EpubConstants.EpubTypeNamespaceUri, "type")); + switch (name) { + case "smil": + vocabs = VocabUtil.parsePrefixDeclaration( + e.getAttributeNS(EpubConstants.EpubTypeNamespaceUri, "prefix"), RESERVED_VOCABS, + KNOWN_VOCAB_URIS, DEFAULT_VOCAB_URIS, report, + EPUBLocation.create(path, parser.getLineNumber(), parser.getColumnNumber())); + break; + + case "body": + case "seq": + case "par": + processGlobalAttrs(e); + break; + + case "text": + processSrc(e); + break; + + case "audio": + processRef(e.getAttribute("src"), XRefChecker.Type.AUDIO); + checkTime(e.getAttribute("clipBegin"), e.getAttribute("clipEnd")); + break; } } @@ -163,6 +162,7 @@ private void processRef(String ref, XRefChecker.Type type) } } else { + checkFragment(ref); String uniqueResource = PathUtil.removeFragment(ref); if (!Strings.isNullOrEmpty(uniqueResource)) { if (!context.overlayTextChecker.get().add(uniqueResource, context.opfItem.get().getId())) { @@ -175,10 +175,12 @@ private void processRef(String ref, XRefChecker.Type type) } } - private void processSeq(XMLElement e) + private void processGlobalAttrs(XMLElement e) { - processRef(e.getAttributeNS(EpubConstants.EpubTypeNamespaceUri, "textref"), - XRefChecker.Type.HYPERLINK); + if (!e.getName().equals("audio")) { + processRef(e.getAttributeNS(EpubConstants.EpubTypeNamespaceUri, "textref"), + XRefChecker.Type.HYPERLINK); + } checkType(e.getAttributeNS(EpubConstants.EpubTypeNamespaceUri, "type")); } @@ -212,4 +214,13 @@ private void checkItemReferences() { } + private void checkFragment(String ref) { + + String frag = PathUtil.getFragment(ref.trim()); + + if (ref.indexOf("#") == -1 || Strings.isNullOrEmpty(frag)) { + // must include a non-empty fragid + report.message(MessageId.MED_014, EPUBLocation.create(path, parser.getLineNumber(), parser.getColumnNumber())); + } + } } diff --git a/src/main/resources/com/adobe/epubcheck/messages/MessageBundle.properties b/src/main/resources/com/adobe/epubcheck/messages/MessageBundle.properties index 41cd66183..b6c3e55e4 100644 --- a/src/main/resources/com/adobe/epubcheck/messages/MessageBundle.properties +++ b/src/main/resources/com/adobe/epubcheck/messages/MessageBundle.properties @@ -137,6 +137,7 @@ MED_010=EPUB Content Documents referenced from a Media Overlay must specify the MED_011=EPUB Content Document referenced from multiple Media Overlay Documents. MED_012=The "media-overlay" attribute does not match the ID of the Media Overlay that refers to this document. MED_013=Media Overlay Document referenced from the "media-overlay" attribute does not contain a reference to this Content Document. +MED_014=A non-empty fragment identifier is required. #NAV EPUB v3 Table of contents NAV_001=The nav file is not supported for EPUB v2. diff --git a/src/test/resources/epub3/files/epub/mediaoverlays-audio-non-cmt-error/EPUB/content_001.smil b/src/test/resources/epub3/files/epub/mediaoverlays-audio-non-cmt-error/EPUB/content_001.smil index c4406fda7..254786ac5 100644 --- a/src/test/resources/epub3/files/epub/mediaoverlays-audio-non-cmt-error/EPUB/content_001.smil +++ b/src/test/resources/epub3/files/epub/mediaoverlays-audio-non-cmt-error/EPUB/content_001.smil @@ -2,7 +2,7 @@ - + diff --git a/src/test/resources/epub3/files/epub/mediaoverlays-audio-non-cmt-error/EPUB/content_001.xhtml b/src/test/resources/epub3/files/epub/mediaoverlays-audio-non-cmt-error/EPUB/content_001.xhtml index 96ea27c7e..28757800c 100644 --- a/src/test/resources/epub3/files/epub/mediaoverlays-audio-non-cmt-error/EPUB/content_001.xhtml +++ b/src/test/resources/epub3/files/epub/mediaoverlays-audio-non-cmt-error/EPUB/content_001.xhtml @@ -5,7 +5,7 @@ Minimal EPUB -

Loomings

+

Loomings

Call me Ishmael.

diff --git a/src/test/resources/epub3/files/epub/mediaoverlays-fragid-invalid-error/EPUB/content_001.mp3 b/src/test/resources/epub3/files/epub/mediaoverlays-fragid-invalid-error/EPUB/content_001.mp3 new file mode 100644 index 000000000..3f140bbc4 Binary files /dev/null and b/src/test/resources/epub3/files/epub/mediaoverlays-fragid-invalid-error/EPUB/content_001.mp3 differ diff --git a/src/test/resources/epub3/files/epub/mediaoverlays-fragid-invalid-error/EPUB/content_001.smil b/src/test/resources/epub3/files/epub/mediaoverlays-fragid-invalid-error/EPUB/content_001.smil new file mode 100644 index 000000000..d76eca32b --- /dev/null +++ b/src/test/resources/epub3/files/epub/mediaoverlays-fragid-invalid-error/EPUB/content_001.smil @@ -0,0 +1,9 @@ + + + + + + + + diff --git a/src/test/resources/epub3/files/epub/mediaoverlays-fragid-invalid-error/EPUB/content_001.xhtml b/src/test/resources/epub3/files/epub/mediaoverlays-fragid-invalid-error/EPUB/content_001.xhtml new file mode 100644 index 000000000..28757800c --- /dev/null +++ b/src/test/resources/epub3/files/epub/mediaoverlays-fragid-invalid-error/EPUB/content_001.xhtml @@ -0,0 +1,11 @@ + + + + + Minimal EPUB + + +

Loomings

+

Call me Ishmael.

+ + diff --git a/src/test/resources/epub3/files/epub/mediaoverlays-fragid-invalid-error/EPUB/nav.xhtml b/src/test/resources/epub3/files/epub/mediaoverlays-fragid-invalid-error/EPUB/nav.xhtml new file mode 100644 index 000000000..240745e63 --- /dev/null +++ b/src/test/resources/epub3/files/epub/mediaoverlays-fragid-invalid-error/EPUB/nav.xhtml @@ -0,0 +1,14 @@ + + + + + Minimal Nav + + + + + diff --git a/src/test/resources/epub3/files/epub/mediaoverlays-fragid-invalid-error/EPUB/package.opf b/src/test/resources/epub3/files/epub/mediaoverlays-fragid-invalid-error/EPUB/package.opf new file mode 100644 index 000000000..d45324410 --- /dev/null +++ b/src/test/resources/epub3/files/epub/mediaoverlays-fragid-invalid-error/EPUB/package.opf @@ -0,0 +1,20 @@ + + + + Minimal EPUB 3.0 + en + NOID + 2017-06-14T00:00:01Z + 2.5s + 2.5s + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/epub3/files/epub/mediaoverlays-fragid-invalid-error/META-INF/container.xml b/src/test/resources/epub3/files/epub/mediaoverlays-fragid-invalid-error/META-INF/container.xml new file mode 100644 index 000000000..318782179 --- /dev/null +++ b/src/test/resources/epub3/files/epub/mediaoverlays-fragid-invalid-error/META-INF/container.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/test/resources/epub3/files/epub/mediaoverlays-fragid-invalid-error/mimetype b/src/test/resources/epub3/files/epub/mediaoverlays-fragid-invalid-error/mimetype new file mode 100644 index 000000000..57ef03f24 --- /dev/null +++ b/src/test/resources/epub3/files/epub/mediaoverlays-fragid-invalid-error/mimetype @@ -0,0 +1 @@ +application/epub+zip \ No newline at end of file diff --git a/src/test/resources/epub3/files/epub/mediaoverlays-fragid-resolve-error/EPUB/content_001.mp3 b/src/test/resources/epub3/files/epub/mediaoverlays-fragid-resolve-error/EPUB/content_001.mp3 new file mode 100644 index 000000000..3f140bbc4 Binary files /dev/null and b/src/test/resources/epub3/files/epub/mediaoverlays-fragid-resolve-error/EPUB/content_001.mp3 differ diff --git a/src/test/resources/epub3/files/epub/mediaoverlays-fragid-resolve-error/EPUB/content_001.smil b/src/test/resources/epub3/files/epub/mediaoverlays-fragid-resolve-error/EPUB/content_001.smil new file mode 100644 index 000000000..6db0af2e6 --- /dev/null +++ b/src/test/resources/epub3/files/epub/mediaoverlays-fragid-resolve-error/EPUB/content_001.smil @@ -0,0 +1,11 @@ + + + + + + + + + + diff --git a/src/test/resources/epub3/files/epub/mediaoverlays-fragid-resolve-error/EPUB/content_001.xhtml b/src/test/resources/epub3/files/epub/mediaoverlays-fragid-resolve-error/EPUB/content_001.xhtml new file mode 100644 index 000000000..28757800c --- /dev/null +++ b/src/test/resources/epub3/files/epub/mediaoverlays-fragid-resolve-error/EPUB/content_001.xhtml @@ -0,0 +1,11 @@ + + + + + Minimal EPUB + + +

Loomings

+

Call me Ishmael.

+ + diff --git a/src/test/resources/epub3/files/epub/mediaoverlays-fragid-resolve-error/EPUB/nav.xhtml b/src/test/resources/epub3/files/epub/mediaoverlays-fragid-resolve-error/EPUB/nav.xhtml new file mode 100644 index 000000000..240745e63 --- /dev/null +++ b/src/test/resources/epub3/files/epub/mediaoverlays-fragid-resolve-error/EPUB/nav.xhtml @@ -0,0 +1,14 @@ + + + + + Minimal Nav + + + + + diff --git a/src/test/resources/epub3/files/epub/mediaoverlays-fragid-resolve-error/EPUB/package.opf b/src/test/resources/epub3/files/epub/mediaoverlays-fragid-resolve-error/EPUB/package.opf new file mode 100644 index 000000000..d45324410 --- /dev/null +++ b/src/test/resources/epub3/files/epub/mediaoverlays-fragid-resolve-error/EPUB/package.opf @@ -0,0 +1,20 @@ + + + + Minimal EPUB 3.0 + en + NOID + 2017-06-14T00:00:01Z + 2.5s + 2.5s + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/epub3/files/epub/mediaoverlays-fragid-resolve-error/META-INF/container.xml b/src/test/resources/epub3/files/epub/mediaoverlays-fragid-resolve-error/META-INF/container.xml new file mode 100644 index 000000000..318782179 --- /dev/null +++ b/src/test/resources/epub3/files/epub/mediaoverlays-fragid-resolve-error/META-INF/container.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/test/resources/epub3/files/epub/mediaoverlays-fragid-resolve-error/mimetype b/src/test/resources/epub3/files/epub/mediaoverlays-fragid-resolve-error/mimetype new file mode 100644 index 000000000..57ef03f24 --- /dev/null +++ b/src/test/resources/epub3/files/epub/mediaoverlays-fragid-resolve-error/mimetype @@ -0,0 +1 @@ +application/epub+zip \ No newline at end of file diff --git a/src/test/resources/epub3/files/epub/mediaoverlays-minimal-valid/EPUB/content_001.smil b/src/test/resources/epub3/files/epub/mediaoverlays-minimal-valid/EPUB/content_001.smil index 73d8477bb..11a9a791c 100644 --- a/src/test/resources/epub3/files/epub/mediaoverlays-minimal-valid/EPUB/content_001.smil +++ b/src/test/resources/epub3/files/epub/mediaoverlays-minimal-valid/EPUB/content_001.smil @@ -2,7 +2,7 @@ - + diff --git a/src/test/resources/epub3/files/epub/mediaoverlays-minimal-valid/EPUB/content_001.xhtml b/src/test/resources/epub3/files/epub/mediaoverlays-minimal-valid/EPUB/content_001.xhtml index 96ea27c7e..28757800c 100644 --- a/src/test/resources/epub3/files/epub/mediaoverlays-minimal-valid/EPUB/content_001.xhtml +++ b/src/test/resources/epub3/files/epub/mediaoverlays-minimal-valid/EPUB/content_001.xhtml @@ -5,7 +5,7 @@ Minimal EPUB -

Loomings

+

Loomings

Call me Ishmael.

diff --git a/src/test/resources/epub3/mediaoverlays-publication.feature b/src/test/resources/epub3/mediaoverlays-publication.feature index 1a6bc4201..e0a570e46 100644 --- a/src/test/resources/epub3/mediaoverlays-publication.feature +++ b/src/test/resources/epub3/mediaoverlays-publication.feature @@ -28,7 +28,17 @@ Feature: EPUB 3 ▸ Media Overlays ▸ Full Publication Checks Then error MED-011 is reported And no other errors or warnings are reported - ### The audio Element + Scenario: Report empty fragment identifiers + When checking EPUB 'mediaoverlays-fragid-invalid-error' + Then error MED-014 is reported 2 times + And no other errors or warnings are reported + + Scenario: Report a fragment identifier that does not resolve to an element + When checking EPUB 'mediaoverlays-fragid-resolve-error' + Then error RSC-012 is reported + And no other errors or warnings are reported + + ### 2.4.8 The audio Element Scenario: Report an audio clip that is not a Core Media Type When checking EPUB 'mediaoverlays-audio-non-cmt-error'