Skip to content

Commit

Permalink
feat: loosen restriction on where remote resources can be referenced
Browse files Browse the repository at this point in the history
Previously, EPUBCheck only allowed remote resources when they were
used in elements we knew allowed remote resources (e.g. audio, video,
font declaration).

This commit improves this check by first checking that the resource media
type allows remote resources, regardless of where the resource is used.

Fix #1288
  • Loading branch information
rdeltour committed Jan 24, 2022
1 parent 15825a5 commit 73fe57c
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/main/java/com/adobe/epubcheck/opf/XRefChecker.java
Expand Up @@ -326,7 +326,17 @@ private void checkReference(Reference ref)
&& !(version == EPUBVersion.VERSION_3 && res != null && res.item.isInSpine())
// audio, video, and fonts can be remote resources in EPUB 3
&& !(version == EPUBVersion.VERSION_3
&& EnumSet.of(Type.AUDIO, Type.VIDEO, Type.FONT).contains(ref.type)))
&& (res != null
// if the item is declared, check its mime type
&& (OPFChecker30.isAudioType(res.item.getMimeType())
|| OPFChecker30.isVideoType(res.item.getMimeType())
|| OPFChecker30.isFontType(res.item.getMimeType()))
// else, check if the reference is a type allowing remote resources
|| ref.type == Type.FONT
|| ref.type == Type.AUDIO
|| ref.type == Type.VIDEO
)
))
{
report.message(MessageId.RSC_006,
EPUBLocation.create(ref.source, ref.lineNumber, ref.columnNumber, ref.refResource));
Expand Down
@@ -0,0 +1,11 @@
<!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>
<!-- remote http URL -->
<object data="https://example.org/remote.mp4" type="audio/mp4">audio</object>
</body>
</html>
@@ -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>
@@ -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" properties="remote-resources"/>
<item id="nav" href="nav.xhtml" media-type="application/xhtml+xml" properties="nav"/>
<item id="audio" href="https://example.org/remote.mp4" media-type="audio/mp4" />
</manifest>
<spine>
<itemref idref="content_001" />
</spine>
</package>
@@ -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>
@@ -0,0 +1 @@
application/epub+zip
@@ -0,0 +1,11 @@
<!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>
<!-- remote http URL -->
<object data="https://example.org/remote.mp4" type="video/mp4">video</object>
</body>
</html>
@@ -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>
@@ -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" properties="remote-resources"/>
<item id="nav" href="nav.xhtml" media-type="application/xhtml+xml" properties="nav"/>
<item id="video" href="https://example.org/remote.mp4" media-type="video/mp4" />
</manifest>
<spine>
<itemref idref="content_001" />
</spine>
</package>
@@ -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>
@@ -0,0 +1 @@
application/epub+zip
10 changes: 10 additions & 0 deletions src/test/resources/epub3/resources-publication.feature
Expand Up @@ -108,6 +108,11 @@ Feature: EPUB 3 ▸ Publication Resources ▸ Full Publication Checks
When checking EPUB 'resources-remote-audio-valid'
Then no errors or warnings are reported

Scenario: Verify that remote audio resources are allowed anywhere
(not only in `audio` elements)
When checking EPUB 'resources-remote-audio-object-valid'
Then no errors or warnings are reported

Scenario: Verify that remote audio resources defined in the `sources` element are allowed
When checking EPUB 'resources-remote-audio-sources-valid'
Then no errors or warnings are reported
Expand All @@ -120,6 +125,11 @@ Feature: EPUB 3 ▸ Publication Resources ▸ Full Publication Checks
When checking EPUB 'resources-remote-video-valid'
Then no errors or warnings are reported

Scenario: Verify that remote video resources are allowed anywhere
(not only in `video` elements)
When checking EPUB 'resources-remote-audio-object-valid'
Then no errors or warnings are reported

Scenario: Report a reference to a remote resource from an `iframe` element when the resource is declared in the package document (issue 852)
When checking EPUB 'resources-remote-iframe-error'
Then error RSC-006 is reported
Expand Down

0 comments on commit 73fe57c

Please sign in to comment.