Skip to content

Commit c3d767c

Browse files
committed
fix: OPF-018 was incorrectly reported with inline CSS
`OPF-018` checks that the `remote-resources` property is not defined if no remote resource was found. Prior to this commit, it was incorrectly reported when an XHTML content document carrying the property also contained inline CSS: the CSS checker thought that the property was not required since no remote resource was found in the CSS itself. This commit fixes that bug by only checking `OPF-018` for standalone CSS documents. Fix #1335
1 parent 545b7f7 commit c3d767c

File tree

13 files changed

+142
-13
lines changed

13 files changed

+142
-13
lines changed

src/main/java/com/adobe/epubcheck/css/CSSChecker.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public class CSSChecker extends PublicationResourceChecker
4545
private int line; // where css string occurs in host
4646
private final boolean isStyleAttribute;
4747

48-
private enum Mode
48+
enum Mode
4949
{
5050
FILE,
5151
STRING
@@ -94,7 +94,7 @@ protected boolean checkContent()
9494
try
9595
{
9696

97-
CSSHandler handler = new CSSHandler(context);
97+
CSSHandler handler = new CSSHandler(context, mode);
9898
if (this.mode == Mode.STRING && this.line > -1)
9999
{
100100
handler.setStartingLineNumber(this.line);

src/main/java/com/adobe/epubcheck/css/CSSHandler.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import com.adobe.epubcheck.api.EPUBLocation;
2626
import com.adobe.epubcheck.api.Report;
27+
import com.adobe.epubcheck.css.CSSChecker.Mode;
2728
import com.adobe.epubcheck.messages.MessageId;
2829
import com.adobe.epubcheck.opf.OPFChecker;
2930
import com.adobe.epubcheck.opf.OPFChecker30;
@@ -43,6 +44,7 @@ public class CSSHandler implements CssContentHandler, CssErrorHandler
4344
final ValidationContext context;
4445
final Report report;
4546
final EPUBVersion version;
47+
final Mode mode;
4648
int startingLineNumber = 0; // append to line info from css parser
4749
int startingColumnNumber = 0;
4850
static final CharMatcher SPACE_AND_QUOTES = CharMatcher.anyOf(" \t\n\r\f\"'").precomputed();
@@ -64,11 +66,12 @@ public class CSSHandler implements CssContentHandler, CssErrorHandler
6466
// properties the must be declared on the related OPF item
6567
final Set<ITEM_PROPERTIES> detectedProperties = EnumSet.noneOf(ITEM_PROPERTIES.class);
6668

67-
public CSSHandler(ValidationContext context)
69+
public CSSHandler(ValidationContext context, Mode mode)
6870
{
6971
this.context = context;
7072
this.report = context.report;
7173
this.version = context.version;
74+
this.mode = mode;
7275
this.urlChecker = new URLChecker(context);
7376
}
7477

@@ -447,17 +450,21 @@ protected void checkProperties()
447450
EPUBLocation.of(context).at(startingLineNumber, startingColumnNumber),
448451
PackageVocabs.ITEM_VOCAB.getName(property));
449452
}
450-
451-
// Check that properties declared in the OPF item were found in the content
452-
Set<ITEM_PROPERTIES> uncheckedProperties = Sets
453-
.difference(declaredProperties, detectedProperties)
454-
.copyInto(EnumSet.noneOf(ITEM_PROPERTIES.class));
455-
if (uncheckedProperties.contains(ITEM_PROPERTIES.REMOTE_RESOURCES))
456-
{
457-
uncheckedProperties.remove(ITEM_PROPERTIES.REMOTE_RESOURCES);
458-
report.message(MessageId.OPF_018,
459-
EPUBLocation.of(context).at(startingLineNumber, startingColumnNumber));
453+
454+
if (mode == Mode.FILE) {
455+
// Check that properties declared in the OPF item were found in the content
456+
// We only check this for standalone CSS documents (not CSS inlined in HTML)
457+
Set<ITEM_PROPERTIES> uncheckedProperties = Sets
458+
.difference(declaredProperties, detectedProperties)
459+
.copyInto(EnumSet.noneOf(ITEM_PROPERTIES.class));
460+
if (uncheckedProperties.contains(ITEM_PROPERTIES.REMOTE_RESOURCES))
461+
{
462+
uncheckedProperties.remove(ITEM_PROPERTIES.REMOTE_RESOURCES);
463+
report.message(MessageId.OPF_018,
464+
EPUBLocation.of(context).at(startingLineNumber, startingColumnNumber));
465+
}
460466
}
467+
461468
}
462469

463470
public void setStartingLineNumber(int offset)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html xmlns:epub="http://www.idpf.org/2007/ops" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
3+
lang="en">
4+
<head>
5+
<meta charset="utf-8" />
6+
<title>Minimal EPUB</title>
7+
<style>
8+
@font-face {
9+
font-family: "Open Sans";
10+
src: url("https://example.org/font") format("woff");
11+
}</style>
12+
</head>
13+
<body>
14+
<h1>Loomings</h1>
15+
<p>Call me Ishmael.</p>
16+
</body>
17+
</html>
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>
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" 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+
<item id="font" href="https://example.org/font" media-type="font/woff"/>
13+
</manifest>
14+
<spine>
15+
<itemref idref="content_001" />
16+
</spine>
17+
</package>
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>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
application/epub+zip
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html xmlns:epub="http://www.idpf.org/2007/ops" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
3+
lang="en">
4+
<head>
5+
<meta charset="utf-8" />
6+
<title>Minimal EPUB</title>
7+
<style>
8+
.red {
9+
color: red;
10+
}</style>
11+
</head>
12+
<body>
13+
<h1>Loomings</h1>
14+
<p>Call me Ishmael.</p>
15+
<video src="https://example.org/video.mp4"></video>
16+
</body>
17+
</html>
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>
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" 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" properties="remote-resources"/>
11+
<item id="nav" href="nav.xhtml" media-type="application/xhtml+xml" properties="nav"/>
12+
<item id="video" href="https://example.org/video.mp4" media-type="video/mp4"/>
13+
</manifest>
14+
<spine>
15+
<itemref idref="content_001" />
16+
</spine>
17+
</package>

0 commit comments

Comments
 (0)