Skip to content

Commit

Permalink
feat: any file extension is now allowed
Browse files Browse the repository at this point in the history
EPUB 3.3 has no longer any requirement for file extensions.
EPUBCheck only checked the extension of XHTML files, this check is
now suppressed.

This commit:
- removes the check for `.xhtml` (supresses `HTM_014a`)
- keeps the old check for EPUB 2.0.1
- add tests for various file extensions

Fox #1223
  • Loading branch information
rdeltour committed Jan 24, 2022
1 parent f989588 commit bdee846
Show file tree
Hide file tree
Showing 27 changed files with 218 additions and 16 deletions.
Expand Up @@ -107,7 +107,7 @@ private void initialize()
severities.put(MessageId.HTM_012, Severity.USAGE);
severities.put(MessageId.HTM_013, Severity.USAGE);
severities.put(MessageId.HTM_014, Severity.WARNING);
severities.put(MessageId.HTM_014a, Severity.WARNING);
severities.put(MessageId.HTM_014a, Severity.SUPPRESSED);
severities.put(MessageId.HTM_015, Severity.SUPPRESSED);
severities.put(MessageId.HTM_016, Severity.SUPPRESSED);
severities.put(MessageId.HTM_017, Severity.ERROR);
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/com/adobe/epubcheck/opf/OPFChecker30.java
Expand Up @@ -113,12 +113,6 @@ protected void checkItem(OPFItem item, OPFHandler opfHandler)
report.message(MessageId.OPF_091,
EPUBLocation.create(path, item.getLineNumber(), item.getColumnNumber()));
}
if ("application/xhtml+xml".equals(mimeType)
&& !"xhtml".equals(Files.getFileExtension(PathUtil.removeFragment(item.getPath()))))
{
report.message(MessageId.HTM_014a,
EPUBLocation.create(path, item.getLineNumber(), item.getColumnNumber()), item.getPath());
}

// Note: item fallback existence is checked in schematron, i.e.:
// opfHandler.getItemById(item.getFallback().get()).isPresent() == true
Expand Down
16 changes: 8 additions & 8 deletions src/test/resources/epub3/content-publication.feature
Expand Up @@ -15,6 +15,10 @@ Feature: EPUB 3 ▸ Content Documents ▸ Full Publication Checks

## 2. XHTML Content Documents

Scenario: Verify that an XHTML Content Document can have any extension
When checking EPUB 'content-xhtml-file-extension-unusual-valid'
Then no errors or warnings are reported

### 2.2 Content Conformance

Scenario: Report RelaxNG schema errors when checking a Content Document in a full publication
Expand Down Expand Up @@ -244,14 +248,6 @@ Feature: EPUB 3 ▸ Content Documents ▸ Full Publication Checks
And no other errors or warnings are reported


#### File Properties

Scenario: Report an XHTML content document without an `.xhtml` extension
When checking EPUB 'content-xhtml-extension-warning'
Then warning HTM-014a is reported
And no other errors or warnings are reported


### 2.5 HTML Deviations and Constraints

#### 2.5.5 Foreign Resource Restrictions
Expand Down Expand Up @@ -306,6 +302,10 @@ Feature: EPUB 3 ▸ Content Documents ▸ Full Publication Checks
Then error RSC-015 is reported
And no other errors or warnings are reported

Scenario: Verify that an SVG Content Document can have any extension
When checking EPUB 'content-svg-file-extension-unusual-valid'
Then no errors or warnings are reported


## 4. CSS Style Sheets

Expand Down
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg viewBox="0 0 1200 400" xmlns="http://www.w3.org/2000/svg" xml:lang="en">
<title>SVG Content Document</title>
<desc>Rectangle</desc>
<rect x="10" y="20" width="75" height="30" style="stroke: #333366; fill: #6666cc"/>
</svg>
@@ -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.img">content 001</a></li>
</ol>
</nav>
</body>
</html>
@@ -0,0 +1,16 @@
<?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.img" media-type="image/svg+xml"/>
<item id="nav" href="nav.xhtml" media-type="application/xhtml+xml" properties="nav"/>
</manifest>
<spine>
<itemref idref="content_001" />
</spine>
</package>
@@ -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>
@@ -0,0 +1 @@
application/epub+zip
@@ -0,0 +1,11 @@
<!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>
</body>
</html>
@@ -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.web">content 001</a></li>
</ol>
</nav>
</body>
</html>
@@ -0,0 +1,16 @@
<?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.web" 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>
@@ -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>
@@ -0,0 +1 @@
application/epub+zip
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<smil xmlns="http://www.w3.org/ns/SMIL" xmlns:epub="http://www.idpf.org/2007/ops" version="3.0">
<body>
<par id="par1">
<text src="content_001.xhtml#c01"/>
<audio src="content_001.mp3"/>
</par>
</body>
</smil>
Binary file not shown.
@@ -0,0 +1,11 @@
<!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 id="c01">Loomings</h1>
<p>Call me Ishmael.</p>
</body>
</html>
@@ -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>
@@ -0,0 +1,20 @@
<?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>
<meta property="media:duration">2.5s</meta>
<meta property="media:duration" refines="#mo_001">2.5s</meta>
</metadata>
<manifest>
<item id="content_001" href="content_001.xhtml" media-type="application/xhtml+xml" media-overlay="mo_001"/>
<item id="mo_001" href="content_001.mo" media-type="application/smil+xml"/>
<item id="audio_001" href="content_001.mp3" media-type="audio/mpeg"/>
<item id="nav" href="nav.xhtml" media-type="application/xhtml+xml" properties="nav"/>
</manifest>
<spine>
<itemref idref="content_001" />
</spine>
</package>
@@ -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>
@@ -0,0 +1 @@
application/epub+zip
@@ -0,0 +1,11 @@
<!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>
</body>
</html>
@@ -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>
@@ -0,0 +1,16 @@
<?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"/>
</manifest>
<spine>
<itemref idref="content_001" />
</spine>
</package>
@@ -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.pkg" media-type="application/oebps-package+xml"/>
</rootfiles>
</container>
@@ -0,0 +1 @@
application/epub+zip
4 changes: 4 additions & 0 deletions src/test/resources/epub3/mediaoverlays-publication.feature
Expand Up @@ -18,6 +18,10 @@ Feature: EPUB 3 ▸ Media Overlays ▸ Full Publication Checks
When checking EPUB 'mediaoverlays-minimal-valid'
Then no errors or warnings are reported

Scenario: Verify that a Media Overlays Document can have any extension
When checking EPUB 'mediaoverlays-file-extension-unusual-valid'
Then no errors or warnings are reported


## 2. Media Overlay Document Definition

Expand Down
6 changes: 5 additions & 1 deletion src/test/resources/epub3/package-publication.feature
Expand Up @@ -15,10 +15,14 @@ Feature: EPUB 3 ▸ Packages ▸ Full Publication Checks

Scenario: Verify a minimal EPUB
When checking EPUB 'minimal'
Then no errors or warnings are reported
Then no errors or warnings are reported

## 3. Package Document

Scenario: Verify that the Package Document can have any extension
When checking EPUB 'package-file-extension-unusual-valid'
Then no errors or warnings are reported

### 3.4.1 The package Element

# FIXME the current API doesn’t allow the version to be explicitly set
Expand Down

0 comments on commit bdee846

Please sign in to comment.