Skip to content

Commit 1b425fd

Browse files
committed
fix: allow remote URLs in HTML "cite" attributes
The resources referenced in `cite` attribute URLs are not publication resources. This commit disables the publication-resource-specific URL checks for the `cite` attribute. For instance, the referenced document is not subject to resource location restrictions. The URL is still registered in the reference registry, so that the existence of the underlying container resource is checked (for relative URLs). Fix #1495
1 parent 2370940 commit 1b425fd

File tree

8 files changed

+62
-6
lines changed

8 files changed

+62
-6
lines changed

src/main/java/com/adobe/epubcheck/ops/OPSHandler30.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ else if (name.equals("blockquote") || name.equals("q") || name.equals("ins")
448448

449449
private void checkCiteAttribute()
450450
{
451-
URL url = checkResourceURL(currentElement().getAttribute("cite"));
451+
URL url = checkURL(currentElement().getAttribute("cite"));
452452
registerReference(url, Type.CITE);
453453
}
454454

src/main/java/org/w3c/epubcheck/core/references/ResourceReferencesChecker.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ else if (MIMEType.SVG.is(targetMimetype) && !fragment.isValid())
177177
report.message(MessageId.RSC_012, reference.location.context(reference.url.toString()));
178178
throw new CheckAbortException();
179179
}
180-
180+
181181
switch (reference.type)
182182
{
183183
case SVG_PAINT:
@@ -189,6 +189,7 @@ else if (MIMEType.SVG.is(targetMimetype) && !fragment.isValid())
189189
}
190190
break;
191191
case SVG_SYMBOL:
192+
case CITE:
192193
case HYPERLINK:
193194
case OVERLAY_TEXT_LINK:
194195
if (targetIDType != reference.type && targetIDType != Reference.Type.GENERIC)
@@ -334,7 +335,8 @@ else if (!undeclared.contains(reference.targetResource)
334335
// links and remote hyperlinks are not Publication Resources
335336
&& !(reference.type == Reference.Type.LINK
336337
|| container.isRemote(reference.targetResource)
337-
&& reference.type == Reference.Type.HYPERLINK))
338+
&& (reference.type == Reference.Type.HYPERLINK
339+
|| reference.type == Reference.Type.CITE)))
338340
{
339341
undeclared.add(reference.targetResource);
340342
report.message(MessageId.RSC_008, reference.location,
@@ -351,7 +353,8 @@ private void checkRemoteReference(Reference reference, Optional<Resource> target
351353

352354
// Check if the remote reference is allowed
353355
if (// remote links and hyperlinks are not Publication Resources
354-
!EnumSet.of(Reference.Type.LINK, Reference.Type.HYPERLINK).contains(reference.type)
356+
!EnumSet.of(Reference.Type.CITE, Reference.Type.LINK, Reference.Type.HYPERLINK)
357+
.contains(reference.type)
355358
// spine items are checked in OPFChecker30
356359
&& !(version == EPUBVersion.VERSION_3 && targetResource.isPresent()
357360
&& targetResource.get().isInSpine())
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html xmlns:epub="http://www.idpf.org/2007/ops" 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+
<q cite="https://example.org/cite.html">text</q>
11+
</body>
12+
</html>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en" lang="en">
3+
<head>
4+
<meta charset="utf-8"/>
5+
<title>Minimal Nav</title>
6+
</head>
7+
<body>
8+
<nav epub:type="toc">
9+
<ol>
10+
<li><a href="content_001.xhtml">content 001</a></li>
11+
</ol>
12+
</nav>
13+
</body>
14+
</html>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
</manifest>
13+
<spine>
14+
<itemref idref="content_001" />
15+
</spine>
16+
</package>
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>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
application/epub+zip

src/test/resources/epub3/04-ocf/ocf.feature

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,12 @@ Feature: EPUB 3 — Open Container Format
156156

157157
#### resource existence checks:
158158

159+
Scenario: Allow an absolute `cite` URL
160+
When checking EPUB 'url-xhtml-cite-absolute-valid'
161+
Then no errors or warnings are reported
162+
159163
@spec @xref:sec-container-iri
160-
Scenario: Report a reference from an XHTML `cite` attribute not declared in the manifest
164+
Scenario: Report a relative `cite` URL when the resource is not found in the manifest
161165
When checking EPUB 'url-xhtml-cite-missing-resource-error'
162166
Then error RSC-007 is reported 4 times
163167
And no other errors or warnings are reported
@@ -168,7 +172,7 @@ Feature: EPUB 3 — Open Container Format
168172
Then error RSC-007 is reported
169173
And no other errors or warnings are reported
170174

171-
@spec @xref:sec-exempt-resources
175+
@spec @xref:sec-container-iri
172176
Scenario: Report a reference from an XHTML `track` not declared in the manifest
173177
When checking EPUB 'url-xhtml-track-missing-resource-error'
174178
Then error RSC-007 is reported

0 commit comments

Comments
 (0)