Skip to content

Commit b2c5d8c

Browse files
committed
fix: items were listed twice and/or with null values in the JSON report
This was caused by a regression after the refactoring of the parsing of the container structure and package documents. This commit adds a new feature file to write tests for the JSON report. The first test scenarios check basic assertions: - JSON is well-formed - the items array has the correct number of items (no items duplication) - the checksum field Fix #1475, Fix #1490
1 parent 13a11b9 commit b2c5d8c

File tree

8 files changed

+69
-7
lines changed

8 files changed

+69
-7
lines changed

src/main/java/com/adobe/epubcheck/ocf/OCFChecker.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import java.util.HashSet;
2929
import java.util.LinkedList;
3030
import java.util.List;
31-
import java.util.Map;
3231
import java.util.Set;
3332

3433
import org.w3c.epubcheck.constants.MIMEType;
@@ -319,7 +318,7 @@ private boolean checkContainerStructure(OCFCheckerState state)
319318
new OCFFilenameChecker(resource.getPath(), state.context().build()).check();
320319

321320
// Report entry metadata
322-
reportFeatures(resource.getProperties());
321+
reportFeatures(resource);
323322

324323
// Add the resource to the container model
325324
state.addResource(resource);
@@ -553,11 +552,12 @@ private EPUBVersion checkPublicationVersion(OCFCheckerState state)
553552
}
554553
}
555554

556-
private void reportFeatures(Map<FeatureEnum, String> features)
555+
private void reportFeatures(OCFResource resource)
557556
{
558-
for (FeatureEnum feature : features.keySet())
557+
for (FeatureEnum feature : resource.getProperties().keySet())
559558
{
560-
report.info(context.path, feature, features.get(feature));
559+
// report.info(context.path, feature, resource.getProperties().get(feature));
560+
report.info(resource.getPath(), feature, resource.getProperties().get(feature));
561561
}
562562
}
563563

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,6 @@ else if (name.equals("item"))
287287

288288
String mediaOverlay = e.getAttribute("media-overlay");
289289
itemBuilder.mediaOverlay(mediaOverlay);
290-
291-
report.info(href, FeatureEnum.UNIQUE_IDENT, id);
292290
}
293291
}
294292
}
@@ -641,6 +639,7 @@ private void buildItems()
641639
*/
642640
protected void reportItem(OPFItem item)
643641
{
642+
report.info(item.getPath(), FeatureEnum.UNIQUE_IDENT, item.getId());
644643
if (item.isInSpine())
645644
{
646645
report.info(item.getPath(), FeatureEnum.IS_SPINEITEM, "true");
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html xmlns:epub="http://www.idpf.org/2007/ops" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3+
<head>
4+
<meta charset="utf-8"/>
5+
<title>Minimal EPUB</title>
6+
</head>
7+
<body>
8+
<h1>Loomings</h1>
9+
<p>Call me Ishmael.</p>
10+
</body>
11+
</html>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en" lang="en">
3+
<head>
4+
<meta charset="utf-8"/>
5+
<title>Minimal Nav</title>
6+
</head>
7+
<body>
8+
<nav epub:type="toc">
9+
<ol>
10+
<li><a href="content_001.xhtml">content 001</a></li>
11+
</ol>
12+
</nav>
13+
</body>
14+
</html>
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" xml:lang="en" unique-identifier="q">
3+
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/">
4+
<dc:title id="title">Minimal EPUB 3.0</dc:title>
5+
<dc:language>en</dc:language>
6+
<dc:identifier id="q">NOID</dc:identifier>
7+
<meta property="dcterms:modified">2017-06-14T00:00:01Z</meta>
8+
</metadata>
9+
<manifest>
10+
<item id="content_001" href="content_001.xhtml" media-type="application/xhtml+xml"/>
11+
<item id="nav" href="nav.xhtml" media-type="application/xhtml+xml" properties="nav"/>
12+
</manifest>
13+
<spine>
14+
<itemref idref="content_001" />
15+
</spine>
16+
</package>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
3+
<rootfiles>
4+
<rootfile full-path="EPUB/package.opf" media-type="application/oebps-package+xml"/>
5+
</rootfiles>
6+
</container>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
application/epub+zip
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Feature: EPUBCheck - JSON Report tests
2+
3+
Checks the JSON report format
4+
5+
6+
Background:
7+
Given EPUB test files located at '/reporting/files/'
8+
And the reporting format is set to JSON
9+
And EPUBCheck with default settings
10+
11+
Scenario: Basic well-formedness checks
12+
When checking EPUB 'minimal'
13+
Then the JSON report is valid
14+
And JSON at '$.items' contains 5 items
15+
And JSON at '$..checkSum' has no null values

0 commit comments

Comments
 (0)