Skip to content

Commit

Permalink
feat: check that publication resources are not in META-INF
Browse files Browse the repository at this point in the history
EPUB 3.3 now explicitly forbids creators to refernce files in the
META-INF directory from an EPUB Publication.

This commit:
- adds a new check PKG-025 to report Package Document items that
  reference files in the META-INF directory
- add tests

Fix #1227
  • Loading branch information
rdeltour committed Jan 24, 2022
1 parent bdee846 commit 61dbf53
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ private void initialize()
severities.put(MessageId.PKG_022, Severity.WARNING);
severities.put(MessageId.PKG_023, Severity.USAGE);
severities.put(MessageId.PKG_024, Severity.INFO);
severities.put(MessageId.PKG_025, Severity.ERROR);

// Resources
severities.put(MessageId.RSC_001, Severity.ERROR);
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 @@ -294,6 +294,7 @@ public enum MessageId implements Comparable<MessageId>
PKG_022("PKG-022"),
PKG_023("PKG-023"),
PKG_024("PKG-024"),
PKG_025("PKG-025"),

// Messages relating to resources
RSC_001("RSC-001"),
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/adobe/epubcheck/opf/OPFChecker30.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ protected boolean checkContent()
@Override
protected void checkItem(OPFItem item, OPFHandler opfHandler)
{
if (item.getPath().startsWith("META-INF/")) {
report.message(MessageId.PKG_025,
EPUBLocation.create(path, item.getLineNumber(), item.getColumnNumber()));
}

String mimeType = item.getMimeType();
if (mimeType == null || mimeType.equals(""))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ PKG_022=Wrong file extension for image. The image is a "%1$s" file but has the f
PKG_023=Validating the EPUB against version 2.0, default validation profile will be used.
PKG_024=Uncommon EPUB file extension.
PKG_024_SUG=For maximum compatibility, use ".epub".
PKG_025=Publication resource must not be located in the META-INF directory

#Resources
RSC_001=File "%1$s" could not be found.
Expand Down
5 changes: 5 additions & 0 deletions src/test/resources/epub3/container-publication.feature
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ Feature: EPUB 3 ▸ Open Container Format ▸ Full Publication Checks
Then error PKG-007 is reported
And no other errors or warnings are reported

Scenario: Report publication resources found in META-INF
When checking EPUB 'ocf-meta-inf-with-publication-resource-error'
Then error PKG-025 is reported
And no other errors or warnings are reported


### 3.4 File Names

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html 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>
<img src="../META-INF/image.jpeg" alt="" />
</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="content_001" href="content_001.xhtml" media-type="application/xhtml+xml"/>
<item id="nav" href="nav.xhtml" media-type="application/xhtml+xml" properties="nav"/>
<item id="image" href="../META-INF/image.jpeg" media-type="image/jpeg"/>
</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>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
application/epub+zip

0 comments on commit 61dbf53

Please sign in to comment.