Skip to content

Commit 199da0b

Browse files
committed
fix: allow the 'cover-image' property on WebP images
Prior to this commit, we used a hardcoded list of MIME types to check that the 'cover-image' property was used on images (CMT only). Now, we only check that the MIME type stars with 'image/'. Fix #1484
1 parent 3c8dab3 commit 199da0b

File tree

4 files changed

+48
-5
lines changed

4 files changed

+48
-5
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ private void processItemProperties(OPFItem.Builder builder, String property, Str
519519
mimeType = mimeType.trim();
520520
for (ITEM_PROPERTIES itemProp : itemProps)
521521
{
522-
if (!itemProp.allowedOnTypes().contains(mimeType))
522+
if (!itemProp.isAllowedForType(mimeType))
523523
{
524524
report.message(MessageId.OPF_012, location(), ITEM_VOCAB.getName(itemProp), mimeType);
525525
}

src/main/java/com/adobe/epubcheck/vocab/PackageVocabs.java

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static enum META_PROPERTIES
4242

4343
public static enum ITEM_PROPERTIES
4444
{
45-
COVER_IMAGE("image/gif", "image/jpeg", "image/png", "image/svg+xml"),
45+
COVER_IMAGE("image/*"),
4646
DATA_NAV("application/xhtml+xml"),
4747
DICTIONARY("application/vnd.epub.search-key-map+xml"),
4848
GLOSSARY("application/vnd.epub.search-key-map+xml", "application/xhtml+xml"),
@@ -59,12 +59,33 @@ public static enum ITEM_PROPERTIES
5959

6060
private ITEM_PROPERTIES(String... types)
6161
{
62-
this.types = new ImmutableSet.Builder<String>().add(types).build();
62+
ImmutableSet.Builder<String> builder = new ImmutableSet.Builder<String>();
63+
for (String type : types)
64+
{
65+
if (type.endsWith("/*"))
66+
{
67+
builder.add(type.substring(0, type.length() - 1));
68+
}
69+
else
70+
{
71+
builder.add(type);
72+
}
73+
}
74+
this.types = builder.build();
6375
}
6476

65-
public Set<String> allowedOnTypes()
77+
public boolean isAllowedForType(String mimetype)
6678
{
67-
return types;
79+
if (mimetype == null) return false;
80+
for (String allowedType : types)
81+
{
82+
if (allowedType.equals(mimetype)
83+
|| allowedType.endsWith("/") && mimetype.startsWith(allowedType))
84+
{
85+
return true;
86+
}
87+
}
88+
return false;
6889
}
6990
}
7091

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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:title>Title</dc:title>
6+
<dc:language>en</dc:language>
7+
<dc:identifier id="uid">NOID</dc:identifier>
8+
<meta property="dcterms:modified">2019-01-01T12:00:00Z</meta>
9+
</metadata>
10+
<manifest>
11+
<item id="t001" href="contents.xhtml" properties="nav" media-type="application/xhtml+xml"/>
12+
<item id="cover" href="cover.webp" media-type="image/webp" properties="cover-image" />
13+
</manifest>
14+
<spine>
15+
<itemref idref="t001"/>
16+
</spine>
17+
</package>

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,11 @@ Feature: EPUB 3 — Package document
523523

524524
##### cover-image
525525

526+
@spec @xref:sec-item-resource-properties
527+
Scenario: The 'cover-image' item property is allowed on WebP images
528+
When checking file 'item-property-cover-image-webp-valid.opf'
529+
Then no other errors or warnings are reported
530+
526531
@spec @xref:sec-item-resource-properties
527532
Scenario: The 'cover-image' item property must occur at most once
528533
When checking file 'item-property-cover-image-multiple-error.opf'

0 commit comments

Comments
 (0)