Skip to content

Commit dd00b88

Browse files
committed
feat: report package link to package document elements
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
1 parent 09244a4 commit dd00b88

File tree

6 files changed

+36
-5
lines changed

6 files changed

+36
-5
lines changed

src/main/java/com/adobe/epubcheck/messages/DefaultSeverities.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ private void initialize()
292292
severities.put(MessageId.OPF_096, Severity.ERROR);
293293
severities.put(MessageId.OPF_096b, Severity.USAGE);
294294
severities.put(MessageId.OPF_097, Severity.USAGE);
295+
severities.put(MessageId.OPF_098, Severity.ERROR);
295296

296297
// PKG
297298
severities.put(MessageId.PKG_001, Severity.WARNING);

src/main/java/com/adobe/epubcheck/messages/MessageId.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ public enum MessageId implements Comparable<MessageId>
286286
OPF_096("OPF-096"),
287287
OPF_096b("OPF-096b"),
288288
OPF_097("OPF-097"),
289+
OPF_098("OPF-098"),
289290

290291
// Messages relating to the entire package
291292
PKG_001("PKG-001"),

src/main/java/com/adobe/epubcheck/opf/OPFHandler30.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,10 +400,20 @@ private void processLink()
400400
if (url != null)
401401
{
402402
// Data URLs are not allowed on `link` elements
403-
if ("data".equals(url.scheme())) {
403+
if ("data".equals(url.scheme()))
404+
{
404405
report.message(MessageId.RSC_029, location());
405406
return;
406407
}
408+
// The `href` attribute MUST not reference resources via elements
409+
// in the package document itself
410+
if (url.fragment() != null && !url.fragment().isEmpty()
411+
&& URLUtils.docURL(url).equals(context.url))
412+
{
413+
report.message(MessageId.OPF_098, location(), href);
414+
return;
415+
}
416+
407417
if (context.isRemote(url))
408418
{
409419
report.info(path, FeatureEnum.REFERENCE, href);

src/main/resources/com/adobe/epubcheck/messages/MessageBundle.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ OPF_094=The "media-type" attribute is required for "%1$s" links.
213213
OPF_095=The "media-type" attribute of "voicing" links must be an audio MIME type, but found "%1$s".
214214
OPF_096=Non-linear content must be reachable, but found no hyperlink to "%1$s".
215215
OPF_096b=No hyperlink was found to non-linear document "%1$s", please check that it can be reached from scripted content.
216-
OPF_097=Resource "%1$s" is listed in the manifest, but no reference to it was found in content documents.
216+
OPF_097=Resource "%1$s" is listed in the manifest, but no reference to it was found in content documents.
217+
OPF_098=The "href" attribute must not reference resources via elements in the package document itself, but found URL "%1$s".
217218

218219
#Package
219220
PKG_001=Validating the EPUB against version %1$s but detected version %2$s.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<package xmlns="http://www.idpf.org/2007/opf" version="3.0" unique-identifier="uid"
3+
xmlns:dc="http://purl.org/dc/elements/1.1/"
4+
prefix="example: https:example.org">
5+
<metadata>
6+
<dc:title>Title</dc:title>
7+
<dc:language>en</dc:language>
8+
<dc:identifier id="uid">NOID</dc:identifier>
9+
<meta property="dcterms:modified">2019-01-01T12:00:00Z</meta>
10+
<!-- link MUST NOT reference resources via elements in the package document -->
11+
<link rel="example:property" href="#t001" media-type="application/xhtml+xml"/>
12+
</metadata>
13+
<manifest>
14+
<item id="t001" href="contents.xhtml" properties="nav" media-type="application/xhtml+xml"/>
15+
</manifest>
16+
<spine>
17+
<itemref idref="t001"/>
18+
</spine>
19+
</package>

src/test/resources/epub3/05-package-document/package-document.feature

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,11 @@ Feature: EPUB 3 — Package document
3131

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

3838

39-
4039
### 5.3.3 The id attribute
4140

4241
Scenario: 'id' attributes can have leading or trailing space

0 commit comments

Comments
 (0)