Skip to content

Commit

Permalink
feat: add new Core Media Types (ECMAScript, OPUS, WebP)
Browse files Browse the repository at this point in the history
Added the following Core Media Types:
- "audio/opus"
- "image/webp"
- "application/ecmascript"

Also added some missing tests for some older core media types.

Fix #1249, Fix #1189
  • Loading branch information
rdeltour committed Nov 14, 2021
1 parent ec28b59 commit 166256a
Show file tree
Hide file tree
Showing 45 changed files with 356 additions and 19 deletions.
8 changes: 4 additions & 4 deletions src/main/java/com/adobe/epubcheck/opf/OPFChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,10 @@ public static boolean isDeprecatedBlessedStyleType(String type)
return type.equals("text/x-oeb1-css");
}

public static boolean isBlessedImageType(String type)
public static boolean isBlessedImageType(String type, EPUBVersion version)
{
return type.equals("image/gif") || type.equals("image/png") || type.equals("image/jpeg")
|| type.equals("image/svg+xml");
|| type.equals("image/svg+xml") || version == EPUBVersion.VERSION_3 && type.equals("image/webp");
}

public static boolean isBlessedFontMimetype20(String mime)
Expand Down Expand Up @@ -447,7 +447,7 @@ protected void checkSpineItem(OPFItem item, OPFHandler opfHandler)
// [GC 11/15/09]
String mimeType = item.getMimeType();
if (isBlessedStyleType(mimeType) || isDeprecatedBlessedStyleType(mimeType)
|| isBlessedImageType(mimeType))
|| isBlessedImageType(mimeType, version))
{
report.message(MessageId.OPF_042,
EPUBLocation.create(path, item.getLineNumber(), item.getColumnNumber()), mimeType);
Expand Down Expand Up @@ -542,7 +542,7 @@ boolean checkImageFallbacks(OPFItem item, OPFHandler opfHandler)
if (fallbackItem.isPresent())
{
String mimeType = fallbackItem.get().getMimeType();
if (isBlessedImageType(mimeType))
if (isBlessedImageType(mimeType, opfHandler.context.version))
{
return true;
}
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/adobe/epubcheck/opf/OPFChecker30.java
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ public static boolean isAudioType(String type)

public static boolean isBlessedAudioType(String type)
{
return type.equals("audio/mpeg") || type.equals("audio/mp4");
return type.equals("audio/mpeg") || type.equals("audio/mp4") || type.equals("audio/opus");
}

public static boolean isVideoType(String type)
Expand Down Expand Up @@ -555,13 +555,13 @@ public static boolean isBlessedFontType(String type)
}

public static boolean isBlessedScriptType(String type) {
return type.equals("text/javascript") || type.equals("application/javascript");
return type.equals("text/javascript") || type.equals("application/javascript") || type.equals("application/ecmascript");
}

public static boolean isCoreMediaType(String type)
{
return isBlessedAudioType(type) || isBlessedVideoType(type) || isBlessedFontType(type)
|| isBlessedItemType(type, EPUBVersion.VERSION_3) || isBlessedImageType(type)
|| isBlessedItemType(type, EPUBVersion.VERSION_3) || isBlessedImageType(type, EPUBVersion.VERSION_3)
|| isBlessedScriptType(type)
|| type.equals("application/pls+xml") || type.equals("application/smil+xml")
|| type.equals("image/svg+xml");
Expand All @@ -579,6 +579,7 @@ public static String getPreferredMediaType(String type, String path)
case "application/font-woff":
return "font/woff";
case "text/javascript":
case "application/ecmascript":
return "application/javascript";
default:
return null;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/adobe/epubcheck/opf/XRefChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ else if (!undeclared.contains(ref.refResource)
return;
}
// if mimeType is null, we should have reported an error already
if (!OPFChecker.isBlessedImageType(res.item.getMimeType()))
if (!OPFChecker.isBlessedImageType(res.item.getMimeType(), version))
{
if (version == EPUBVersion.VERSION_3 && ref.type == Type.PICTURE_SOURCE) {
report.message(MessageId.MED_007,
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/adobe/epubcheck/ops/OPSHandler30.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.adobe.epubcheck.opf.OPFChecker30;
import com.adobe.epubcheck.opf.ValidationContext;
import com.adobe.epubcheck.opf.XRefChecker;
import com.adobe.epubcheck.util.EPUBVersion;
import com.adobe.epubcheck.util.EpubConstants;
import com.adobe.epubcheck.util.FeatureEnum;
import com.adobe.epubcheck.util.PathUtil;
Expand Down Expand Up @@ -157,7 +158,7 @@ else if (xrefChecker.isPresent())
String type = e.getAttribute("type");
// if in a 'source' element specifying a foreign MIME type,
// register as foreign picture source
if ("source".equals(e.getName()) && type != null && !OPFChecker.isBlessedImageType(type))
if ("source".equals(e.getName()) && type != null && !OPFChecker.isBlessedImageType(type, EPUBVersion.VERSION_3))
{
registerImageSources(src, srcset, XRefChecker.Type.PICTURE_SOURCE_FOREIGN);
}
Expand Down Expand Up @@ -488,7 +489,7 @@ protected void processVideo(XMLElement e)
posterSrc));
}

if (posterMimeType != null && !OPFChecker.isBlessedImageType(posterMimeType))
if (posterMimeType != null && !OPFChecker.isBlessedImageType(posterMimeType, EPUBVersion.VERSION_3))
{
report.message(MessageId.MED_001,
EPUBLocation.create(path, parser.getLineNumber(), parser.getColumnNumber()));
Expand Down
3 changes: 3 additions & 0 deletions src/test/resources/epub3/content-publication.feature
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ Feature: EPUB 3 ▸ Content Documents ▸ Full Publication Checks
Then error OPF-013 is reported
And no other errors or warnings are reported

##### script

#//TODO verify script core media types

##### SVG

Expand Down
Binary file not shown.
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>
<audio src="audio.foreign" />
</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="audio" href="audio.foreign" media-type="audio/foreign"/>
</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
Binary file not shown.
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>
<audio src="audio.mp3" />
</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="audio" href="audio.mp3" media-type="audio/mpeg"/>
</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
Binary file not shown.
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>
<audio src="audio.mp4" />
</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="audio" href="audio.mp4" media-type="audio/mp4"/>
</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
Binary file not shown.
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>
<audio src="audio.opus" />
</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="audio" href="audio.opus" media-type="audio/opus"/>
</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
@@ -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="image.gif" alt="" />
</body>
</html>
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,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="img" href="image.gif" media-type="image/gif"/>
</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
Loading

0 comments on commit 166256a

Please sign in to comment.