Skip to content

Commit 6e44b39

Browse files
committed
feat: allow SVG/MathML doctype declarations
EPUB 3.3. now allows a reserved set of external identifiers in doctype declarations of documents with select media types. See: https://www.w3.org/TR/epub-33/#app-identifiers-allowed This commit: - adds those as special cases to the XML parser code - totally removes entity fetching for EPUB 3.3 - keeps forbidding external entities in the internal subset Fix #1192, Fix #1114
1 parent ab99f1d commit 6e44b39

File tree

23 files changed

+215
-10
lines changed

23 files changed

+215
-10
lines changed

src/main/java/com/adobe/epubcheck/xml/XMLParser.java

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -313,20 +313,18 @@ public InputSource resolveEntity(String publicId, String systemId)
313313

314314
String resourcePath = systemIdMap.get(systemId);
315315

316-
if (resourcePath != null)
316+
// external entities are not resolved in EPUB 3
317+
if (context.version == EPUBVersion.VERSION_3 || systemId.equals("about:legacy-compat")) {
318+
return new InputSource(new StringReader(""));
319+
}
320+
else if (resourcePath != null)
317321
{
318322
InputStream resourceStream = ResourceUtil.getResourceStream(resourcePath);
319323
InputSource source = new InputSource(resourceStream);
320324
source.setPublicId(publicId);
321325
source.setSystemId(systemId);
322326
return source;
323327
}
324-
else if (systemId.equals("about:legacy-compat"))
325-
{
326-
// special case
327-
return new InputSource(new StringReader(""));
328-
329-
}
330328
else
331329
{
332330
// check for a system prop that turns off online fetching
@@ -797,7 +795,24 @@ else if (context.version == EPUBVersion.VERSION_3)
797795
}
798796
else if (publicId != null || systemId != null)
799797
{
800-
report.message(MessageId.OPF_073, getLocation());
798+
// check if the declaration is allowed for the current media type
799+
boolean isAllowed;
800+
switch (mimeType)
801+
{
802+
case "image/svg+xml":
803+
isAllowed = "-//W3C//DTD SVG 1.1//EN".equals(publicId) && "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd".equals(systemId);
804+
break;
805+
case "application/mathml+xml":
806+
case "application/mathml-content+xml":
807+
case "application/mathml-presentation+xml":
808+
isAllowed = "-//W3C//DTD MathML 3.0//EN".equals(publicId) && "http://www.w3.org/Math/DTD/mathml3/mathml3.dtd".equals(systemId);
809+
break;
810+
default:
811+
isAllowed= false;
812+
}
813+
if (!isAllowed) {
814+
report.message(MessageId.OPF_073, getLocation());
815+
}
801816
}
802817
}
803818

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3+
<head>
4+
<meta charset="utf-8"/>
5+
<title>Minimal EPUB</title>
6+
</head>
7+
<body>
8+
<h1>Loomings</h1>
9+
<p>Call me Ishmael.</p>
10+
</body>
11+
</html>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE math PUBLIC "-//W3C//DTD MathML 3.0//EN" "http://www.w3.org/Math/DTD/mathml3/mathml3.dtd">
3+
<math xmlns="http://www.w3.org/1998/Math/MathML" alttext="2x+y-z">
4+
<mrow>
5+
<mn>2</mn>
6+
<mo> &#x2061;<!--INVISIBLE TIMES--></mo>
7+
<mi>x</mi>
8+
</mrow>
9+
<mrow>
10+
<mo>+</mo>
11+
<mi>y</mi>
12+
<mo>-</mo>
13+
<mi>z</mi>
14+
</mrow>
15+
</math>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE math PUBLIC "-//W3C//DTD MathML 3.0//EN" "http://www.w3.org/Math/DTD/mathml3/mathml3.dtd">
3+
<math xmlns="http://www.w3.org/1998/Math/MathML" alttext="2x+y-z">
4+
<mrow>
5+
<mn>2</mn>
6+
<mo> &#x2061;<!--INVISIBLE TIMES--></mo>
7+
<mi>x</mi>
8+
</mrow>
9+
<mrow>
10+
<mo>+</mo>
11+
<mi>y</mi>
12+
<mo>-</mo>
13+
<mi>z</mi>
14+
</mrow>
15+
</math>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE math PUBLIC "-//W3C//DTD MathML 3.0//EN" "http://www.w3.org/Math/DTD/mathml3/mathml3.dtd">
3+
<math xmlns="http://www.w3.org/1998/Math/MathML" alttext="2x+y-z">
4+
<mrow>
5+
<mn>2</mn>
6+
<mo> &#x2061;<!--INVISIBLE TIMES--></mo>
7+
<mi>x</mi>
8+
</mrow>
9+
<mrow>
10+
<mo>+</mo>
11+
<mi>y</mi>
12+
<mo>-</mo>
13+
<mi>z</mi>
14+
</mrow>
15+
</math>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
</metadata>
9+
<manifest>
10+
<item id="content_001" href="content_001.xhtml" media-type="application/xhtml+xml"/>
11+
<item id="nav" href="nav.xhtml" media-type="application/xhtml+xml" properties="nav"/>
12+
<item id="mathml-1" href="mathml-mediatype-1.xml" media-type="application/mathml+xml" fallback="content_001"/>
13+
<item id="mathml-2" href="mathml-mediatype-2.xml" media-type="application/mathml-presentation+xml" fallback="content_001"/>
14+
<item id="mathml-3" href="mathml-mediatype-3.xml" media-type="application/mathml-content+xml" fallback="content_001"/>
15+
<item id="svg" href="svg.svg" media-type="image/svg+xml"/>
16+
</manifest>
17+
<spine>
18+
<itemref idref="content_001" />
19+
<itemref idref="svg"/>
20+
<itemref idref="mathml-1"/>
21+
<itemref idref="mathml-2"/>
22+
<itemref idref="mathml-3"/>
23+
</spine>
24+
</package>
Lines changed: 7 additions & 0 deletions
Loading
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
3+
<rootfiles>
4+
<rootfile full-path="EPUB/package.opf" media-type="application/oebps-package+xml"/>
5+
</rootfiles>
6+
</container>

0 commit comments

Comments
 (0)