From f4566b636391341f50b8edb09190e9d5aec1fb64 Mon Sep 17 00:00:00 2001 From: MattGarrish Date: Mon, 21 Jan 2019 21:11:45 -0400 Subject: [PATCH] feat: add `application/javascript` as core media type In EPUB 3.2, `application/javascript` replaces `text/javascript` as the preferred media type for scripts in the manifest. Fix #874 --- .../adobe/epubcheck/ctc/EpubScriptCheck.java | 5 ++-- .../com/adobe/epubcheck/opf/OPFChecker30.java | 9 ++++-- .../adobe/epubcheck/opf/OPFCheckerTest.java | 7 +++++ .../resources/30/single/opf/valid/cmt.opf | 29 +++++++++++++++++++ 4 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 src/test/resources/30/single/opf/valid/cmt.opf diff --git a/src/main/java/com/adobe/epubcheck/ctc/EpubScriptCheck.java b/src/main/java/com/adobe/epubcheck/ctc/EpubScriptCheck.java index 36aaee3a4..82cb8acda 100644 --- a/src/main/java/com/adobe/epubcheck/ctc/EpubScriptCheck.java +++ b/src/main/java/com/adobe/epubcheck/ctc/EpubScriptCheck.java @@ -17,6 +17,7 @@ import com.adobe.epubcheck.ctc.xml.ScriptTagHandler; import com.adobe.epubcheck.ctc.xml.XMLContentDocParser; import com.adobe.epubcheck.messages.MessageId; +import com.adobe.epubcheck.opf.OPFChecker30; import com.adobe.epubcheck.opf.DocumentValidator; import com.adobe.epubcheck.util.EPUBVersion; import com.adobe.epubcheck.util.FeatureEnum; @@ -91,13 +92,13 @@ public boolean validate() } return result; } - + void checkJavascript(ManifestItem mi) { InputStream is = null; BufferedReader reader = null; String mediaType = mi.getMediaType(); - if (mediaType != null && "text/javascript".equalsIgnoreCase(mediaType)) + if (mediaType != null && OPFChecker30.isBlessedScriptType(mediaType.toLowerCase())) { String fileToParse = epack.getManifestItemFileName(mi); ZipEntry entry = this.zip.getEntry(fileToParse); diff --git a/src/main/java/com/adobe/epubcheck/opf/OPFChecker30.java b/src/main/java/com/adobe/epubcheck/opf/OPFChecker30.java index 1edc04a59..f14454788 100644 --- a/src/main/java/com/adobe/epubcheck/opf/OPFChecker30.java +++ b/src/main/java/com/adobe/epubcheck/opf/OPFChecker30.java @@ -494,12 +494,17 @@ public static boolean isBlessedFontType(String type) return type.equals("application/vnd.ms-opentype") || type.equals("application/font-woff") || type.equals("image/svg+xml"); } + + public static boolean isBlessedScriptType(String type) { + return type.equals("text/javascript") || type.equals("application/javascript"); + } public static boolean isCoreMediaType(String type) { return isBlessedAudioType(type) || isBlessedVideoType(type) || isBlessedFontType(type) || isBlessedItemType(type, EPUBVersion.VERSION_3) || isBlessedImageType(type) - || type.equals("text/javascript") || type.equals("application/pls+xml") - || type.equals("application/smil+xml") || type.equals("image/svg+xml"); + || isBlessedScriptType(type) + || type.equals("application/pls+xml") || type.equals("application/smil+xml") + || type.equals("image/svg+xml"); } } diff --git a/src/test/java/com/adobe/epubcheck/opf/OPFCheckerTest.java b/src/test/java/com/adobe/epubcheck/opf/OPFCheckerTest.java index 9f04af9ee..85ad767d5 100644 --- a/src/test/java/com/adobe/epubcheck/opf/OPFCheckerTest.java +++ b/src/test/java/com/adobe/epubcheck/opf/OPFCheckerTest.java @@ -129,6 +129,13 @@ public void setup() } + @Test + public void testCMTSupport() + { + // tests that core media types are supported without fallbacks + testValidateDocument("valid/cmt.opf", EPUBVersion.VERSION_3); + } + @Test public void testBindingsIsDeprecated() { diff --git a/src/test/resources/30/single/opf/valid/cmt.opf b/src/test/resources/30/single/opf/valid/cmt.opf new file mode 100644 index 000000000..f0596136e --- /dev/null +++ b/src/test/resources/30/single/opf/valid/cmt.opf @@ -0,0 +1,29 @@ + + + + Minimal EPUB 3.0 + en + NOID + 2017-06-14T00:00:01Z + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file