Skip to content

Commit 54b5f1f

Browse files
committed
fix: allow links to resources embedded in content documents
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
1 parent dd00b88 commit 54b5f1f

File tree

9 files changed

+72
-6
lines changed

9 files changed

+72
-6
lines changed

src/main/java/com/adobe/epubcheck/opf/OPFChecker30.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,10 +412,10 @@ private void checkLinkedResources()
412412
LinkedResources links = ((OPFHandler30) opfHandler).getLinkedResources();
413413
for (LinkedResource link : links.asList())
414414
{
415-
if (opfHandler.getItemByURL(link.getDocumentURL()).isPresent())
415+
Optional<OPFItem> item = opfHandler.getItemByURL(link.getDocumentURL());
416+
if (item.isPresent() && !item.get().isInSpine())
416417
{
417-
// FIXME 2022 check how to report the URL
418-
report.message(MessageId.OPF_067, EPUBLocation.of(context), link.getDocumentURL().path());
418+
report.message(MessageId.OPF_067, EPUBLocation.of(context), item.get().getPath());
419419
}
420420
}
421421
}

src/main/resources/com/adobe/epubcheck/messages/MessageBundle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ OPF_095=The "media-type" attribute of "voicing" links must be an audio MIME type
214214
OPF_096=Non-linear content must be reachable, but found no hyperlink to "%1$s".
215215
OPF_096b=No hyperlink was found to non-linear document "%1$s", please check that it can be reached from scripted content.
216216
OPF_097=Resource "%1$s" is listed in the manifest, but no reference to it was found in content documents.
217-
OPF_098=The "href" attribute must not reference resources via elements in the package document itself, but found URL "%1$s".
217+
OPF_098=The "href" attribute must reference resources, not elements in the package document, but found URL "%1$s".
218218

219219
#Package
220220
PKG_001=Validating the EPUB against version %1$s but detected version %2$s.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!DOCTYPE html>
2+
<html xmlns:epub="http://www.idpf.org/2007/ops" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
3+
lang="en">
4+
<head>
5+
<meta charset="utf-8" />
6+
<title>Minimal EPUB</title>
7+
<script id="meta-json" type="application/ld+json">
8+
{
9+
"@context" : "http://schema.org",
10+
"name" : "test"
11+
}
12+
</script>
13+
</head>
14+
<body>
15+
<h1>Loomings</h1>
16+
<p>Call me Ishmael.</p>
17+
</body>
18+
</html>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en" lang="en">
3+
<head>
4+
<meta charset="utf-8"/>
5+
<title>Minimal Nav</title>
6+
</head>
7+
<body>
8+
<nav epub:type="toc">
9+
<ol>
10+
<li><a href="content_001.xhtml">content 001</a></li>
11+
</ol>
12+
</nav>
13+
</body>
14+
</html>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<package xmlns="http://www.idpf.org/2007/opf" version="3.0" xml:lang="en" unique-identifier="q">
3+
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/">
4+
<dc:title id="title">Minimal EPUB 3.0</dc:title>
5+
<dc:language>en</dc:language>
6+
<dc:identifier id="q">NOID</dc:identifier>
7+
<meta property="dcterms:modified">2017-06-14T00:00:01Z</meta>
8+
<link rel="record" href="content_001.xhtml#meta-json" media-type="application/xhtml+xml" hreflang="en"
9+
/>
10+
</metadata>
11+
<manifest>
12+
<item id="content_001" href="content_001.xhtml" media-type="application/xhtml+xml"/>
13+
<item id="nav" href="nav.xhtml" media-type="application/xhtml+xml" properties="nav"/>
14+
</manifest>
15+
<spine>
16+
<itemref idref="content_001"/>
17+
</spine>
18+
</package>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
3+
<rootfiles>
4+
<rootfile full-path="EPUB/package.opf" media-type="application/oebps-package+xml"/>
5+
</rootfiles>
6+
</container>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
application/epub+zip

src/test/resources/epub3/05-package-document/files/link-to-publication-resource-error.opf renamed to src/test/resources/epub3/05-package-document/files/link-to-spine-item-valid.opf

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
<dc:language>en</dc:language>
88
<dc:identifier id="uid">NOID</dc:identifier>
99
<meta property="dcterms:modified">2019-01-01T12:00:00Z</meta>
10-
<!--Linked resources MUST NOT be listed in the manifest.-->
11-
<link rel="example:property" href="contents.xhtml#ch1" media-type="application/xhtml+xml"/>
10+
<link rel="example:property" href="contents.xhtml" media-type="application/xhtml+xml"/>
1211
</metadata>
1312
<manifest>
1413
<item id="t001" href="contents.xhtml" properties="nav" media-type="application/xhtml+xml"/>

src/test/resources/epub3/05-package-document/package-document.feature

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,16 @@ Feature: EPUB 3 — Package document
382382
When checking file 'link-hreflang-not-well-formed-error.opf'
383383
Then error OPF-092 is reported
384384
And no other errors or warnings are reported
385+
386+
@spec @xref:sec-link-elem
387+
Scenario: Allow a link to a resource referenced from the spine
388+
When checking file 'link-to-spine-item-valid.opf'
389+
Then no errors or warnings are reported
390+
391+
@spec @xref:sec-link-elem
392+
Scenario: Allow a link to a resource embedded in a content document
393+
When checking EPUB 'link-to-embedded-resource-valid'
394+
Then no errors or warnings are reported
385395

386396

387397
### 5.6 Manifest section

0 commit comments

Comments
 (0)