Skip to content

Commit ec28b59

Browse files
committed
feat: check that item URLs have no fragment
Manifest `item` URLs that have a fragment are now reported as `OPF-091` (new check). Fix #1250
1 parent 39888e2 commit ec28b59

6 files changed

Lines changed: 31 additions & 4 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ private void initialize()
272272
severities.put(MessageId.OPF_088, Severity.USAGE);
273273
severities.put(MessageId.OPF_089, Severity.ERROR);
274274
severities.put(MessageId.OPF_090, Severity.USAGE);
275+
severities.put(MessageId.OPF_091, Severity.ERROR);
275276

276277
// PKG
277278
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
@@ -266,6 +266,7 @@ public enum MessageId implements Comparable<MessageId>
266266
OPF_088("OPF-088"),
267267
OPF_089("OPF-089"),
268268
OPF_090("OPF-090"),
269+
OPF_091("OPF-091"),
269270

270271
// Messages relating to the entire package
271272
PKG_001("PKG-001"),

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,12 @@ protected void checkItem(OPFItem item, OPFHandler opfHandler)
106106
EPUBLocation.create(path, item.getLineNumber(), item.getColumnNumber()),
107107
preferredMimeType, mimeType);
108108
}
109-
109+
if (!PathUtil.isRemote(item.getPath()) && PathUtil.getFragment(item.getPath()) != null) {
110+
report.message(MessageId.OPF_091,
111+
EPUBLocation.create(path, item.getLineNumber(), item.getColumnNumber()));
112+
}
110113
if ("application/xhtml+xml".equals(mimeType)
111-
&& !"xhtml".equals(Files.getFileExtension(item.getPath())))
114+
&& !"xhtml".equals(Files.getFileExtension(PathUtil.removeFragment(item.getPath()))))
112115
{
113116
report.message(MessageId.HTM_014a,
114117
EPUBLocation.create(path, item.getLineNumber(), item.getColumnNumber()), item.getPath());

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,8 @@ OPF_086b_SUG.warning=the "notice" property
280280
OPF_087=epub:type value "%1$s" is not allowed on documents of type "%2$s".
281281
OPF_088=Unrecognized epub:type value "%1$s".
282282
OPF_089=The "alternate" link rel keyword cannot be paired with other keywords.
283-
OPF_090=It is encouraged to use MIME media type "%1$s" instead of "%2$s".
283+
OPF_090=It is encouraged to use MIME media type "%1$s" instead of "%2$s".
284+
OPF_091=The item href URL must not have a fragment identifier.
284285

285286
#Package
286287
PKG_001=Validating the EPUB against version %1$s but detected version %2$s.
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" unique-identifier="uid"
3+
xmlns:dc="http://purl.org/dc/elements/1.1/">
4+
<metadata>
5+
<dc:identifier id="uid">xxx</dc:identifier>
6+
<dc:title>Title</dc:title>
7+
<dc:language>en</dc:language>
8+
<meta property="dcterms:modified">2019-01-01T12:00:00Z</meta>
9+
</metadata>
10+
<manifest>
11+
<item id="t001" href="contents.xhtml#id" properties="nav" media-type="application/xhtml+xml"/>
12+
</manifest>
13+
<spine>
14+
<itemref idref="t001"/>
15+
</spine>
16+
</package>

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,16 @@ Feature: EPUB 3 ▸ Packages ▸ Package Document Checks
238238
And the message contains 'missing required attribute "media-type"'
239239
And no other errors or warnings are reported
240240

241-
Scenario: item paths should not contain spaces
241+
Scenario: item URLs should not contain spaces
242242
When checking file 'item-href-contains-spaces-warning.opf'
243243
Then warning PKG-010 is reported
244244
And no other errors or warnings are reported
245245

246+
Scenario: item URLs must not have a fragment identifier
247+
When checking file 'item-href-with-fragment-error.opf'
248+
Then error OPF-091 is reported
249+
And no other errors or warnings are reported
250+
246251
Scenario: two manifest items cannot represent the same resource
247252
When checking file 'item-duplicate-resource-error.opf'
248253
Then error OPF-074 is reported

0 commit comments

Comments
 (0)