Skip to content

Commit

Permalink
fix: allow remote URLs in HTML "cite" attributes
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rdeltour committed Apr 22, 2023
1 parent 2370940 commit 1b425fd
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/adobe/epubcheck/ops/OPSHandler30.java
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ else if (name.equals("blockquote") || name.equals("q") || name.equals("ins")

private void checkCiteAttribute()
{
URL url = checkResourceURL(currentElement().getAttribute("cite"));
URL url = checkURL(currentElement().getAttribute("cite"));
registerReference(url, Type.CITE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ else if (MIMEType.SVG.is(targetMimetype) && !fragment.isValid())
report.message(MessageId.RSC_012, reference.location.context(reference.url.toString()));
throw new CheckAbortException();
}

switch (reference.type)
{
case SVG_PAINT:
Expand All @@ -189,6 +189,7 @@ else if (MIMEType.SVG.is(targetMimetype) && !fragment.isValid())
}
break;
case SVG_SYMBOL:
case CITE:
case HYPERLINK:
case OVERLAY_TEXT_LINK:
if (targetIDType != reference.type && targetIDType != Reference.Type.GENERIC)
Expand Down Expand Up @@ -334,7 +335,8 @@ else if (!undeclared.contains(reference.targetResource)
// links and remote hyperlinks are not Publication Resources
&& !(reference.type == Reference.Type.LINK
|| container.isRemote(reference.targetResource)
&& reference.type == Reference.Type.HYPERLINK))
&& (reference.type == Reference.Type.HYPERLINK
|| reference.type == Reference.Type.CITE)))
{
undeclared.add(reference.targetResource);
report.message(MessageId.RSC_008, reference.location,
Expand All @@ -351,7 +353,8 @@ private void checkRemoteReference(Reference reference, Optional<Resource> target

// Check if the remote reference is allowed
if (// remote links and hyperlinks are not Publication Resources
!EnumSet.of(Reference.Type.LINK, Reference.Type.HYPERLINK).contains(reference.type)
!EnumSet.of(Reference.Type.CITE, Reference.Type.LINK, Reference.Type.HYPERLINK)
.contains(reference.type)
// spine items are checked in OPFChecker30
&& !(version == EPUBVersion.VERSION_3 && targetResource.isPresent()
&& targetResource.get().isInSpine())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html xmlns:epub="http://www.idpf.org/2007/ops" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta charset="utf-8"/>
<title>Minimal EPUB</title>
</head>
<body>
<h1>Loomings</h1>
<p>Call me Ishmael.</p>
<q cite="https://example.org/cite.html">text</q>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?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"/>
<item id="nav" href="nav.xhtml" media-type="application/xhtml+xml" properties="nav"/>
</manifest>
<spine>
<itemref idref="content_001" />
</spine>
</package>
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
application/epub+zip
8 changes: 6 additions & 2 deletions src/test/resources/epub3/04-ocf/ocf.feature
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,12 @@ Feature: EPUB 3 — Open Container Format

#### resource existence checks:

Scenario: Allow an absolute `cite` URL
When checking EPUB 'url-xhtml-cite-absolute-valid'
Then no errors or warnings are reported

@spec @xref:sec-container-iri
Scenario: Report a reference from an XHTML `cite` attribute not declared in the manifest
Scenario: Report a relative `cite` URL when the resource is not found in the manifest
When checking EPUB 'url-xhtml-cite-missing-resource-error'
Then error RSC-007 is reported 4 times
And no other errors or warnings are reported
Expand All @@ -168,7 +172,7 @@ Feature: EPUB 3 — Open Container Format
Then error RSC-007 is reported
And no other errors or warnings are reported

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

0 comments on commit 1b425fd

Please sign in to comment.