diff --git a/src/main/java/com/adobe/epubcheck/messages/DefaultSeverities.java b/src/main/java/com/adobe/epubcheck/messages/DefaultSeverities.java index bdffe6cbe..3c009e114 100644 --- a/src/main/java/com/adobe/epubcheck/messages/DefaultSeverities.java +++ b/src/main/java/com/adobe/epubcheck/messages/DefaultSeverities.java @@ -292,6 +292,7 @@ private void initialize() severities.put(MessageId.OPF_096, Severity.ERROR); severities.put(MessageId.OPF_096b, Severity.USAGE); severities.put(MessageId.OPF_097, Severity.USAGE); + severities.put(MessageId.OPF_098, Severity.ERROR); // PKG severities.put(MessageId.PKG_001, Severity.WARNING); diff --git a/src/main/java/com/adobe/epubcheck/messages/MessageId.java b/src/main/java/com/adobe/epubcheck/messages/MessageId.java index 748996355..108234376 100644 --- a/src/main/java/com/adobe/epubcheck/messages/MessageId.java +++ b/src/main/java/com/adobe/epubcheck/messages/MessageId.java @@ -286,6 +286,7 @@ public enum MessageId implements Comparable OPF_096("OPF-096"), OPF_096b("OPF-096b"), OPF_097("OPF-097"), + OPF_098("OPF-098"), // Messages relating to the entire package PKG_001("PKG-001"), diff --git a/src/main/java/com/adobe/epubcheck/opf/OPFHandler30.java b/src/main/java/com/adobe/epubcheck/opf/OPFHandler30.java index 018f753db..9baca65d5 100644 --- a/src/main/java/com/adobe/epubcheck/opf/OPFHandler30.java +++ b/src/main/java/com/adobe/epubcheck/opf/OPFHandler30.java @@ -400,10 +400,20 @@ private void processLink() if (url != null) { // Data URLs are not allowed on `link` elements - if ("data".equals(url.scheme())) { + if ("data".equals(url.scheme())) + { report.message(MessageId.RSC_029, location()); return; } + // The `href` attribute MUST not reference resources via elements + // in the package document itself + if (url.fragment() != null && !url.fragment().isEmpty() + && URLUtils.docURL(url).equals(context.url)) + { + report.message(MessageId.OPF_098, location(), href); + return; + } + if (context.isRemote(url)) { report.info(path, FeatureEnum.REFERENCE, href); diff --git a/src/main/resources/com/adobe/epubcheck/messages/MessageBundle.properties b/src/main/resources/com/adobe/epubcheck/messages/MessageBundle.properties index 24e140527..b1493bfd0 100644 --- a/src/main/resources/com/adobe/epubcheck/messages/MessageBundle.properties +++ b/src/main/resources/com/adobe/epubcheck/messages/MessageBundle.properties @@ -213,7 +213,8 @@ OPF_094=The "media-type" attribute is required for "%1$s" links. OPF_095=The "media-type" attribute of "voicing" links must be an audio MIME type, but found "%1$s". OPF_096=Non-linear content must be reachable, but found no hyperlink to "%1$s". OPF_096b=No hyperlink was found to non-linear document "%1$s", please check that it can be reached from scripted content. -OPF_097=Resource "%1$s" is listed in the manifest, but no reference to it was found in content documents. +OPF_097=Resource "%1$s" is listed in the manifest, but no reference to it was found in content documents. +OPF_098=The "href" attribute must not reference resources via elements in the package document itself, but found URL "%1$s". #Package PKG_001=Validating the EPUB against version %1$s but detected version %2$s. diff --git a/src/test/resources/epub3/05-package-document/files/link-to-package-document-id-error.opf b/src/test/resources/epub3/05-package-document/files/link-to-package-document-id-error.opf new file mode 100644 index 000000000..e1fb6bca3 --- /dev/null +++ b/src/test/resources/epub3/05-package-document/files/link-to-package-document-id-error.opf @@ -0,0 +1,19 @@ + + + + Title + en + NOID + 2019-01-01T12:00:00Z + + + + + + + + + + diff --git a/src/test/resources/epub3/05-package-document/package-document.feature b/src/test/resources/epub3/05-package-document/package-document.feature index 9542433bd..4b3b72216 100644 --- a/src/test/resources/epub3/05-package-document/package-document.feature +++ b/src/test/resources/epub3/05-package-document/package-document.feature @@ -31,12 +31,11 @@ Feature: EPUB 3 — Package document @spec @xref:attrdef-href Scenario: 'link' target must not reference a manifest ID - When checking file 'link-to-publication-resource-error.opf' - Then error OPF-067 is reported + When checking file 'link-to-package-document-id-error.opf' + Then error OPF-098 is reported And no other errors or warnings are reported - ### 5.3.3 The id attribute Scenario: 'id' attributes can have leading or trailing space