Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: check that item URLs have no fragment #1359

Merged
merged 1 commit into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ private void initialize()
severities.put(MessageId.OPF_088, Severity.USAGE);
severities.put(MessageId.OPF_089, Severity.ERROR);
severities.put(MessageId.OPF_090, Severity.USAGE);
severities.put(MessageId.OPF_091, 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 @@ -266,6 +266,7 @@ public enum MessageId implements Comparable<MessageId>
OPF_088("OPF-088"),
OPF_089("OPF-089"),
OPF_090("OPF-090"),
OPF_091("OPF-091"),

// Messages relating to the entire package
PKG_001("PKG-001"),
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/com/adobe/epubcheck/opf/OPFChecker30.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,12 @@ protected void checkItem(OPFItem item, OPFHandler opfHandler)
EPUBLocation.create(path, item.getLineNumber(), item.getColumnNumber()),
preferredMimeType, mimeType);
}

if (!PathUtil.isRemote(item.getPath()) && PathUtil.getFragment(item.getPath()) != null) {
report.message(MessageId.OPF_091,
EPUBLocation.create(path, item.getLineNumber(), item.getColumnNumber()));
}
if ("application/xhtml+xml".equals(mimeType)
&& !"xhtml".equals(Files.getFileExtension(item.getPath())))
&& !"xhtml".equals(Files.getFileExtension(PathUtil.removeFragment(item.getPath()))))
{
report.message(MessageId.HTM_014a,
EPUBLocation.create(path, item.getLineNumber(), item.getColumnNumber()), item.getPath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@ OPF_086b_SUG.warning=the "notice" property
OPF_087=epub:type value "%1$s" is not allowed on documents of type "%2$s".
OPF_088=Unrecognized epub:type value "%1$s".
OPF_089=The "alternate" link rel keyword cannot be paired with other keywords.
OPF_090=It is encouraged to use MIME media type "%1$s" instead of "%2$s".
OPF_090=It is encouraged to use MIME media type "%1$s" instead of "%2$s".
OPF_091=The item href URL must not have a fragment identifier.

#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,16 @@
<?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/">
<metadata>
<dc:identifier id="uid">xxx</dc:identifier>
<dc:title>Title</dc:title>
<dc:language>en</dc:language>
<meta property="dcterms:modified">2019-01-01T12:00:00Z</meta>
</metadata>
<manifest>
<item id="t001" href="contents.xhtml#id" properties="nav" media-type="application/xhtml+xml"/>
</manifest>
<spine>
<itemref idref="t001"/>
</spine>
</package>
7 changes: 6 additions & 1 deletion src/test/resources/epub3/package-document.feature
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,16 @@ Feature: EPUB 3 ▸ Packages ▸ Package Document Checks
And the message contains 'missing required attribute "media-type"'
And no other errors or warnings are reported

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

Scenario: item URLs must not have a fragment identifier
When checking file 'item-href-with-fragment-error.opf'
Then error OPF-091 is reported
And no other errors or warnings are reported

Scenario: two manifest items cannot represent the same resource
When checking file 'item-duplicate-resource-error.opf'
Then error OPF-074 is reported
Expand Down