Skip to content

Commit

Permalink
feat: report package link to package document elements
Browse files Browse the repository at this point in the history
This commit introduces a new error message (`OPF-098`) to report `href` attributes
containing a URL to package document elements.

This implements a check for the following specification statement:
> The URL string MUST NOT reference resources via elements in the package document
  • Loading branch information
rdeltour committed Dec 23, 2022
1 parent 09244a4 commit dd00b88
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ private void initialize()
severities.put(MessageId.OPF_096, Severity.ERROR);
severities.put(MessageId.OPF_096b, Severity.USAGE);
severities.put(MessageId.OPF_097, Severity.USAGE);
severities.put(MessageId.OPF_098, Severity.ERROR);

// PKG
severities.put(MessageId.PKG_001, Severity.WARNING);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/adobe/epubcheck/messages/MessageId.java
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ public enum MessageId implements Comparable<MessageId>
OPF_096("OPF-096"),
OPF_096b("OPF-096b"),
OPF_097("OPF-097"),
OPF_098("OPF-098"),

// Messages relating to the entire package
PKG_001("PKG-001"),
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/com/adobe/epubcheck/opf/OPFHandler30.java
Original file line number Diff line number Diff line change
Expand Up @@ -400,10 +400,20 @@ private void processLink()
if (url != null)
{
// Data URLs are not allowed on `link` elements
if ("data".equals(url.scheme())) {
if ("data".equals(url.scheme()))
{
report.message(MessageId.RSC_029, location());
return;
}
// The `href` attribute MUST not reference resources via elements
// in the package document itself
if (url.fragment() != null && !url.fragment().isEmpty()
&& URLUtils.docURL(url).equals(context.url))
{
report.message(MessageId.OPF_098, location(), href);
return;
}

if (context.isRemote(url))
{
report.info(path, FeatureEnum.REFERENCE, href);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ OPF_094=The "media-type" attribute is required for "%1$s" links.
OPF_095=The "media-type" attribute of "voicing" links must be an audio MIME type, but found "%1$s".
OPF_096=Non-linear content must be reachable, but found no hyperlink to "%1$s".
OPF_096b=No hyperlink was found to non-linear document "%1$s", please check that it can be reached from scripted content.
OPF_097=Resource "%1$s" is listed in the manifest, but no reference to it was found in content documents.
OPF_097=Resource "%1$s" is listed in the manifest, but no reference to it was found in content documents.
OPF_098=The "href" attribute must not reference resources via elements in the package document itself, but found URL "%1$s".

#Package
PKG_001=Validating the EPUB against version %1$s but detected version %2$s.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<package xmlns="http://www.idpf.org/2007/opf" version="3.0" unique-identifier="uid"
xmlns:dc="http://purl.org/dc/elements/1.1/"
prefix="example: https:example.org">
<metadata>
<dc:title>Title</dc:title>
<dc:language>en</dc:language>
<dc:identifier id="uid">NOID</dc:identifier>
<meta property="dcterms:modified">2019-01-01T12:00:00Z</meta>
<!-- link MUST NOT reference resources via elements in the package document -->
<link rel="example:property" href="#t001" media-type="application/xhtml+xml"/>
</metadata>
<manifest>
<item id="t001" href="contents.xhtml" properties="nav" media-type="application/xhtml+xml"/>
</manifest>
<spine>
<itemref idref="t001"/>
</spine>
</package>
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@ Feature: EPUB 3 — Package document

@spec @xref:attrdef-href
Scenario: 'link' target must not reference a manifest ID
When checking file 'link-to-publication-resource-error.opf'
Then error OPF-067 is reported
When checking file 'link-to-package-document-id-error.opf'
Then error OPF-098 is reported
And no other errors or warnings are reported



### 5.3.3 The id attribute

Scenario: 'id' attributes can have leading or trailing space
Expand Down

0 comments on commit dd00b88

Please sign in to comment.