Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: check that the manifest is not self-referencing #1467

Merged
merged 1 commit into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ private void initialize()
severities.put(MessageId.OPF_096b, Severity.USAGE);
severities.put(MessageId.OPF_097, Severity.USAGE);
severities.put(MessageId.OPF_098, Severity.ERROR);
severities.put(MessageId.OPF_099, Severity.ERROR);

// PKG
severities.put(MessageId.PKG_001, Severity.WARNING);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/adobe/epubcheck/messages/MessageId.java
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ public enum MessageId implements Comparable<MessageId>
OPF_096b("OPF-096b"),
OPF_097("OPF-097"),
OPF_098("OPF-098"),
OPF_099("OPF-099"),

// Messages relating to the entire package
PKG_001("PKG-001"),
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/adobe/epubcheck/opf/OPFChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.w3c.epubcheck.core.Checker;
import org.w3c.epubcheck.core.CheckerFactory;
import org.w3c.epubcheck.core.references.ResourceReferencesChecker;
import org.w3c.epubcheck.util.url.URLUtils;

import com.adobe.epubcheck.api.EPUBLocation;
import com.adobe.epubcheck.api.EPUBProfile;
Expand Down Expand Up @@ -215,6 +216,11 @@ protected boolean checkContent()
// FIXME 2022 check duplicates at build time (in OPFHandler)
report.message(MessageId.OPF_074, item.getLocation(), item.getPath());
}
// check that the manifest does not include the package document itself
else if (item.getURL().equals(context.url))
{
report.message(MessageId.OPF_099, item.getLocation());
}
else
{
checkItem(item, opfHandler);
Expand Down Expand Up @@ -361,6 +367,12 @@ protected void checkItemContent(OPFItem item)
{
return;
}
// Abort if the item is this package document
// (this is disallowed, and reported elsewhere)
if (URLUtils.docURL(item.getURL()).equals(context.url))
{
return;
}
// Create a new validation context for the OPF item
// FIXME 2022 set context OPFItem here
// (instead of from XRefChecker in the builder code)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ 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 reference resources, not elements in the package document, but found URL "%1$s".
OPF_099=The manifest must not list the package document.

#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,17 @@
<?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>
</metadata>
<manifest>
<item id="self" href="./manifest-self-referencing-error.opf" media-type="application/oebps-package+xml"/>
<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,11 @@
<!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>
</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,17 @@
<?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>
</metadata>
<manifest>
<item id="self" href="./package.opf" media-type="application/oebps-package+xml"/>
<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 @@ -422,6 +422,18 @@ Feature: EPUB 3 — Package document
Then error RSC-008 is reported
And no other errors or warnings are reported

@spec @xref:sec-manifest-elem
Scenario: Report a self-referencing manifest (full publication check)
When checking EPUB 'manifest-self-referencing-error'
Then error OPF-099 is reported
And no other errors or warnings are reported

@spec @xref:sec-manifest-elem
Scenario: Report a self-referencing manifest (single file check)
When checking file 'manifest-self-referencing-error.opf'
Then error OPF-099 is reported
And no other errors or warnings are reported

Scenario: Report (usage) a container resource that is not listed in the manifest
Given the reporting level is set to usage
When checking EPUB 'manifest-not-listing-container-resource-usage'
Expand Down