Skip to content

Commit 0175818

Browse files
committed
feat: disallow data URLs in the package document
EPUB 3.3 now disallows data URLs everywhere in the package document (in both `item` and `link` elements). See w3c/epub-specs#2494 Fix #1446
1 parent 003234a commit 0175818

File tree

11 files changed

+45
-119
lines changed

11 files changed

+45
-119
lines changed

src/main/java/com/adobe/epubcheck/opf/OPFChecker30.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ protected boolean checkContent()
8585
@Override
8686
protected void checkItem(OPFItem item, OPFHandler opfHandler)
8787
{
88+
// Items with `data:` URLs are not allowed in EPUB 3
89+
if (item.hasDataURL())
90+
{
91+
report.message(MessageId.RSC_029, item.getLocation());
92+
return;
93+
}
8894
if (item.getPath().startsWith("META-INF/"))
8995
{
9096
report.message(MessageId.PKG_025, item.getLocation());
@@ -182,10 +188,9 @@ else if (!overlayTextChecker.isCorrectOverlay(docURL, mo))
182188
@Override
183189
protected void checkSpineItem(OPFItem item, OPFHandler opfHandler)
184190
{
185-
// Items with `data:` URLs are not allowed in the spine
191+
// Items with `data:` URLs are not allowed and reported earlier
186192
if (item.hasDataURL())
187193
{
188-
report.message(MessageId.RSC_029, item.getLocation());
189194
return;
190195
}
191196

src/main/java/com/adobe/epubcheck/opf/OPFHandler30.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -393,12 +393,17 @@ private void processLink()
393393
{
394394
XMLElement e = currentElement();
395395

396+
// check the 'href' URL
397+
// href presence is checked by schema
396398
String href = e.getAttribute("href");
397-
if (href != null)
398-
{ // href presence is checked by schema
399-
400-
// check the 'href' URL
401-
URL url = checkURL(href);
399+
URL url = checkURL(href);
400+
if (url != null)
401+
{
402+
// Data URLs are not allowed on `link` elements
403+
if ("data".equals(url.scheme())) {
404+
report.message(MessageId.RSC_029, location());
405+
return;
406+
}
402407
if (context.isRemote(url))
403408
{
404409
report.info(path, FeatureEnum.REFERENCE, href);

src/test/resources/epub3/03-resources/files/data-url-in-html-img-foreign-manifest-fallback-valid/EPUB/content_001.xhtml

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/test/resources/epub3/03-resources/files/data-url-in-html-img-foreign-manifest-fallback-valid/EPUB/nav.xhtml

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/test/resources/epub3/03-resources/files/data-url-in-html-img-foreign-manifest-fallback-valid/EPUB/package.opf

Lines changed: 0 additions & 45 deletions
This file was deleted.

src/test/resources/epub3/03-resources/files/data-url-in-html-img-foreign-manifest-fallback-valid/META-INF/container.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/test/resources/epub3/03-resources/files/data-url-in-html-img-foreign-manifest-fallback-valid/mimetype

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<package xmlns="http://www.idpf.org/2007/opf" version="3.0" xml:lang="en" unique-identifier="q">
3+
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/">
4+
<dc:title id="title">Minimal EPUB 3.0</dc:title>
5+
<dc:language>en</dc:language>
6+
<dc:identifier id="q">NOID</dc:identifier>
7+
<meta property="dcterms:modified">2017-06-14T00:00:01Z</meta>
8+
<link rel="alternate" href="data:application/xhtml+xml,%3Ch1%3EHello%3C%2Fh1%3E" media-type="application/xhtml+xml"/>
9+
</metadata>
10+
<manifest>
11+
<item id="nav" href="nav.xhtml" media-type="application/xhtml+xml" properties="nav"/>
12+
<item id="content_001" href="content_001.xhtml" media-type="application/xhtml+xml"/>
13+
</manifest>
14+
<spine>
15+
<itemref idref="content_001"/>
16+
</spine>
17+
</package>

0 commit comments

Comments
 (0)