Skip to content

Commit

Permalink
fix: allow links to resources embedded in content documents
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rdeltour committed Jan 3, 2023
1 parent dd00b88 commit 54b5f1f
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/main/java/com/adobe/epubcheck/opf/OPFChecker30.java
Original file line number Diff line number Diff line change
Expand Up @@ -412,10 +412,10 @@ private void checkLinkedResources()
LinkedResources links = ((OPFHandler30) opfHandler).getLinkedResources();
for (LinkedResource link : links.asList())
{
if (opfHandler.getItemByURL(link.getDocumentURL()).isPresent())
Optional<OPFItem> 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());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ OPF_095=The "media-type" attribute of "voicing" links must be an audio MIME type
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_098=The "href" attribute must not reference resources via elements in the package document itself, but found URL "%1$s".
OPF_098=The "href" attribute must reference resources, not elements in the package document, but found URL "%1$s".

#Package
PKG_001=Validating the EPUB against version %1$s but detected version %2$s.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html xmlns:epub="http://www.idpf.org/2007/ops" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
lang="en">
<head>
<meta charset="utf-8" />
<title>Minimal EPUB</title>
<script id="meta-json" type="application/ld+json">
{
"@context" : "http://schema.org",
"name" : "test"
}
</script>
</head>
<body>
<h1>Loomings</h1>
<p>Call me Ishmael.</p>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en" lang="en">
<head>
<meta charset="utf-8"/>
<title>Minimal Nav</title>
</head>
<body>
<nav epub:type="toc">
<ol>
<li><a href="content_001.xhtml">content 001</a></li>
</ol>
</nav>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<package xmlns="http://www.idpf.org/2007/opf" version="3.0" xml:lang="en" unique-identifier="q">
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/">
<dc:title id="title">Minimal EPUB 3.0</dc:title>
<dc:language>en</dc:language>
<dc:identifier id="q">NOID</dc:identifier>
<meta property="dcterms:modified">2017-06-14T00:00:01Z</meta>
<link rel="record" href="content_001.xhtml#meta-json" media-type="application/xhtml+xml" hreflang="en"
/>
</metadata>
<manifest>
<item id="content_001" href="content_001.xhtml" media-type="application/xhtml+xml"/>
<item id="nav" href="nav.xhtml" media-type="application/xhtml+xml" properties="nav"/>
</manifest>
<spine>
<itemref idref="content_001"/>
</spine>
</package>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
<rootfiles>
<rootfile full-path="EPUB/package.opf" media-type="application/oebps-package+xml"/>
</rootfiles>
</container>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
application/epub+zip
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
<dc:language>en</dc:language>
<dc:identifier id="uid">NOID</dc:identifier>
<meta property="dcterms:modified">2019-01-01T12:00:00Z</meta>
<!--Linked resources MUST NOT be listed in the manifest.-->
<link rel="example:property" href="contents.xhtml#ch1" media-type="application/xhtml+xml"/>
<link rel="example:property" href="contents.xhtml" media-type="application/xhtml+xml"/>
</metadata>
<manifest>
<item id="t001" href="contents.xhtml" properties="nav" media-type="application/xhtml+xml"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 54b5f1f

Please sign in to comment.