From 74871c62810418f8bbc46a1348aef5e1e6c6c343 Mon Sep 17 00:00:00 2001 From: Romain Deltour Date: Wed, 21 Dec 2022 17:03:53 +0100 Subject: [PATCH] fix: allow links to resources embedded in content documents MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit checks that the linked resource is not in the spine before reporting `OPF-067` ("The resource "…" must not be listed both as a "link" element in the package metadata and as a manifest item."). Effectively, this allows package links to publication resources in the two cases identified in the EPUB 3.3 specification: > Resources referenced from the link element are publication resources > only when they are: > - referenced from the spine; or > - included or embedded in an EPUB content document Fix #1454 --- .../com/adobe/epubcheck/opf/OPFChecker30.java | 6 +++--- .../EPUB/content_001.xhtml | 18 ++++++++++++++++++ .../EPUB/nav.xhtml | 14 ++++++++++++++ .../EPUB/package.opf | 18 ++++++++++++++++++ .../META-INF/container.xml | 6 ++++++ .../link-to-embedded-resource-valid/mimetype | 1 + ...-error.opf => link-to-spine-item-valid.opf} | 3 +-- .../package-document.feature | 10 ++++++++++ 8 files changed, 71 insertions(+), 5 deletions(-) create mode 100644 src/test/resources/epub3/05-package-document/files/link-to-embedded-resource-valid/EPUB/content_001.xhtml create mode 100644 src/test/resources/epub3/05-package-document/files/link-to-embedded-resource-valid/EPUB/nav.xhtml create mode 100644 src/test/resources/epub3/05-package-document/files/link-to-embedded-resource-valid/EPUB/package.opf create mode 100644 src/test/resources/epub3/05-package-document/files/link-to-embedded-resource-valid/META-INF/container.xml create mode 100644 src/test/resources/epub3/05-package-document/files/link-to-embedded-resource-valid/mimetype rename src/test/resources/epub3/05-package-document/files/{link-to-publication-resource-error.opf => link-to-spine-item-valid.opf} (79%) diff --git a/src/main/java/com/adobe/epubcheck/opf/OPFChecker30.java b/src/main/java/com/adobe/epubcheck/opf/OPFChecker30.java index 77e104c66..9fc249562 100644 --- a/src/main/java/com/adobe/epubcheck/opf/OPFChecker30.java +++ b/src/main/java/com/adobe/epubcheck/opf/OPFChecker30.java @@ -412,10 +412,10 @@ private void checkLinkedResources() LinkedResources links = ((OPFHandler30) opfHandler).getLinkedResources(); for (LinkedResource link : links.asList()) { - if (opfHandler.getItemByURL(link.getDocumentURL()).isPresent()) + Optional item = opfHandler.getItemByURL(link.getDocumentURL()); + if (item.isPresent() && !item.get().isInSpine()) { - // FIXME 2022 check how to report the URL - report.message(MessageId.OPF_067, EPUBLocation.of(context), link.getDocumentURL().path()); + report.message(MessageId.OPF_067, EPUBLocation.of(context), item.get().getPath()); } } } diff --git a/src/test/resources/epub3/05-package-document/files/link-to-embedded-resource-valid/EPUB/content_001.xhtml b/src/test/resources/epub3/05-package-document/files/link-to-embedded-resource-valid/EPUB/content_001.xhtml new file mode 100644 index 000000000..3304c26e9 --- /dev/null +++ b/src/test/resources/epub3/05-package-document/files/link-to-embedded-resource-valid/EPUB/content_001.xhtml @@ -0,0 +1,18 @@ + + + + + Minimal EPUB + + + +

Loomings

+

Call me Ishmael.

+ + diff --git a/src/test/resources/epub3/05-package-document/files/link-to-embedded-resource-valid/EPUB/nav.xhtml b/src/test/resources/epub3/05-package-document/files/link-to-embedded-resource-valid/EPUB/nav.xhtml new file mode 100644 index 000000000..240745e63 --- /dev/null +++ b/src/test/resources/epub3/05-package-document/files/link-to-embedded-resource-valid/EPUB/nav.xhtml @@ -0,0 +1,14 @@ + + + + + Minimal Nav + + + + + diff --git a/src/test/resources/epub3/05-package-document/files/link-to-embedded-resource-valid/EPUB/package.opf b/src/test/resources/epub3/05-package-document/files/link-to-embedded-resource-valid/EPUB/package.opf new file mode 100644 index 000000000..955cc04e4 --- /dev/null +++ b/src/test/resources/epub3/05-package-document/files/link-to-embedded-resource-valid/EPUB/package.opf @@ -0,0 +1,18 @@ + + + + Minimal EPUB 3.0 + en + NOID + 2017-06-14T00:00:01Z + + + + + + + + + + diff --git a/src/test/resources/epub3/05-package-document/files/link-to-embedded-resource-valid/META-INF/container.xml b/src/test/resources/epub3/05-package-document/files/link-to-embedded-resource-valid/META-INF/container.xml new file mode 100644 index 000000000..318782179 --- /dev/null +++ b/src/test/resources/epub3/05-package-document/files/link-to-embedded-resource-valid/META-INF/container.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/test/resources/epub3/05-package-document/files/link-to-embedded-resource-valid/mimetype b/src/test/resources/epub3/05-package-document/files/link-to-embedded-resource-valid/mimetype new file mode 100644 index 000000000..57ef03f24 --- /dev/null +++ b/src/test/resources/epub3/05-package-document/files/link-to-embedded-resource-valid/mimetype @@ -0,0 +1 @@ +application/epub+zip \ No newline at end of file diff --git a/src/test/resources/epub3/05-package-document/files/link-to-publication-resource-error.opf b/src/test/resources/epub3/05-package-document/files/link-to-spine-item-valid.opf similarity index 79% rename from src/test/resources/epub3/05-package-document/files/link-to-publication-resource-error.opf rename to src/test/resources/epub3/05-package-document/files/link-to-spine-item-valid.opf index 0430ba6cf..bbd9f6914 100644 --- a/src/test/resources/epub3/05-package-document/files/link-to-publication-resource-error.opf +++ b/src/test/resources/epub3/05-package-document/files/link-to-spine-item-valid.opf @@ -7,8 +7,7 @@ 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 4b3b72216..46810f114 100644 --- a/src/test/resources/epub3/05-package-document/package-document.feature +++ b/src/test/resources/epub3/05-package-document/package-document.feature @@ -382,6 +382,16 @@ Feature: EPUB 3 — Package document When checking file 'link-hreflang-not-well-formed-error.opf' Then error OPF-092 is reported And no other errors or warnings are reported + + @spec @xref:sec-link-elem + Scenario: Allow a link to a resource referenced from the spine + When checking file 'link-to-spine-item-valid.opf' + Then no errors or warnings are reported + + @spec @xref:sec-link-elem + Scenario: Allow a link to a resource embedded in a content document + When checking EPUB 'link-to-embedded-resource-valid' + Then no errors or warnings are reported ### 5.6 Manifest section