Skip to content

Commit

Permalink
feat: add application/javascript as core media type
Browse files Browse the repository at this point in the history
In EPUB 3.2, `application/javascript` replaces `text/javascript` as the
preferred media type for scripts in the manifest.

Fix #874
  • Loading branch information
mattgarrish authored and rdeltour committed Jan 29, 2019
1 parent ef5b94c commit f4566b6
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/main/java/com/adobe/epubcheck/ctc/EpubScriptCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/com/adobe/epubcheck/opf/OPFChecker30.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
7 changes: 7 additions & 0 deletions src/test/java/com/adobe/epubcheck/opf/OPFCheckerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
29 changes: 29 additions & 0 deletions src/test/resources/30/single/opf/valid/cmt.opf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?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="css" href="epub.css" media-type="text/css"/>
<item id="js_001" href="script_001.js" media-type="application/javascript"/>
<item id="js_002" href="script_002.js" media-type="text/javascript"/>
<item id="font_001" href="font_001.otf" media-type="application/vnd.ms-opentype"/>
<item id="font_002" href="font_002.woff" media-type="application/font-woff"/>
<item id="font_003" href="font_003.svg" media-type="image/svg+xml"/>
<item id="content_001" href="content_001.xhtml" media-type="application/xhtml+xml"/>
<item id="audio_001" href="audio_001.mpg" media-type="audio/mpeg"/>
<item id="audio_002" href="audio_002.mp4" media-type="audio/mp4"/>
<item id="video_001" href="video_001.webm" media-type="video/webm"/>
<item id="video_002" href="video_002.mp4" media-type="video/mp4"/>
<item id="video_003" href="video_003.mp4" media-type="video/h264"/>
<item id="pls_001" href="pls_001.pls" media-type="application/pls+xml"/>
<item id="smil_001" href="smil_001.smil" media-type="application/smil+xml"/>
<item id="nav" href="nav.xhtml" media-type="application/xhtml+xml" properties="nav"/>
</manifest>
<spine>
<itemref idref="content_001" />
</spine>
</package>

0 comments on commit f4566b6

Please sign in to comment.