Skip to content

Commit

Permalink
feat: HTML link element resources do not require fallbacks
Browse files Browse the repository at this point in the history
EPUB 3.3 clarifies the situation of fallbacks for HTML `link` elements.

This commit:
- fully suppresses error CSS-010 that was reported for foreign linked
  stylesheet resources (e.g. XPGT) with no manifest fallbacks
- add a test to verify that other foreign linked resources do not
  require manifest fallbacks

Fix #1247
  • Loading branch information
rdeltour committed Jan 24, 2022
1 parent d0f12a9 commit 8d77b0f
Show file tree
Hide file tree
Showing 17 changed files with 11 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private void initialize()
severities.put(MessageId.CSS_007, Severity.INFO);
severities.put(MessageId.CSS_008, Severity.ERROR);
severities.put(MessageId.CSS_009, Severity.USAGE);
severities.put(MessageId.CSS_010, Severity.ERROR);
severities.put(MessageId.CSS_010, Severity.SUPPRESSED);
severities.put(MessageId.CSS_011, Severity.SUPPRESSED);
severities.put(MessageId.CSS_012, Severity.USAGE);
severities.put(MessageId.CSS_013, Severity.USAGE);
Expand Down
36 changes: 0 additions & 36 deletions src/main/java/com/adobe/epubcheck/ops/OPSHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ int getColumnNumber()
protected boolean hasTh = false;
protected boolean hasThead = false;
protected boolean hasCaption = false;
protected Optional<EPUBLocation> nonStandardStylesheetLink = Optional.absent();
protected boolean hasCss = false;
protected boolean epubTypeInUse = false;
protected boolean checkedUnsupportedXMLVersion = false;
protected StringBuilder textNode;
Expand Down Expand Up @@ -147,36 +145,6 @@ protected void checkLink(XMLElement e, String attrNS, String attr)
href = PathUtil.resolveRelativeReference(base, href);
xrefChecker.get().registerReference(path, parser.getLineNumber(), parser.getColumnNumber(),
href, XRefChecker.Type.STYLESHEET);

// Check the mimetype to record possible non-standard stylesheets
// with no fallback
String mimetype = xrefChecker.get().getMimeType(href);
if (mimetype != null)
{
if (OPFChecker.isBlessedStyleType(mimetype)
|| OPFChecker.isDeprecatedBlessedStyleType(mimetype))
{
hasCss = true;
}
else
{
nonStandardStylesheetLink = Optional.of(
EPUBLocation.create(path, parser.getLineNumber(), parser.getColumnNumber(), href));
}
}
}
}

protected void checkStylesheetFallback()
{
// stylesheet is considered as having "built-in" fallback if
// at least one is found with a blessed CMT (i.e. text/css).
// Implem note: xrefChecker is necessarily present if
// nonStandardStylesheetLink is present.
if (nonStandardStylesheetLink.isPresent() && !hasCss && !xrefChecker.get()
.hasValidFallback(nonStandardStylesheetLink.get().getContext().get()).or(false))
{
report.message(MessageId.CSS_010, nonStandardStylesheetLink.get());
}
}

Expand Down Expand Up @@ -522,10 +490,6 @@ public void endElement()
}
textNode = null;
}
else if ("head".equals(name))
{
checkStylesheetFallback();
}
else if ("table".equals(name))
{
if (tableDepth > 0)
Expand Down
8 changes: 5 additions & 3 deletions src/test/resources/epub3/content-publication.feature
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ Feature: EPUB 3 ▸ Content Documents ▸ Full Publication Checks
Then error RSC-014 is reported
Then no other errors or warnings are reported


Scenario: Verify a linked resource without a fallback
When checking EPUB 'content-xhtml-link-no-fallback-valid'
And no errors or warnings are reported

##### iframes

Scenario: Verify that an `iframe` can reference another XHTML document
Expand Down Expand Up @@ -243,8 +246,7 @@ Feature: EPUB 3 ▸ Content Documents ▸ Full Publication Checks

Scenario: Report an xpgt style sheet without a fallback
See issues #271, #241
When checking EPUB 'content-xhtml-xpgt-no-fallback-error'
Then error CSS-010 is reported
When checking EPUB 'content-xhtml-link-no-fallback-valid'
And no other errors or warnings are reported


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8"/>
<title>Minimal EPUB</title>
<link type="text/css" rel="stylesheet" href="style.css" />
<link rel="alternate" href="test.txt"/>
</head>
<body>
<h1>Loomings</h1>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<manifest>
<item id="content_001" href="content_001.xhtml" media-type="application/xhtml+xml"/>
<item id="nav" href="nav.xhtml" media-type="application/xhtml+xml" properties="nav"/>
<item id="css" href="style.css" media-type="xhtml/css" />
<item id="text" href="test.txt" media-type="text/plain" />
</manifest>
<spine>
<itemref idref="content_001" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<container xmlns="urn:oasis:names:tc:opendocument:xmlns:container" version="1.0">
<?xml version="1.0" encoding="UTF-8" ?>
<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
<rootfiles>
<rootfile full-path="EPUB/package.opf" media-type="application/oebps-package+xml"/>
</rootfiles>
Expand Down

This file was deleted.

5 changes: 0 additions & 5 deletions src/test/resources/epub3/package-publication.feature
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,6 @@ Feature: EPUB 3 ▸ Packages ▸ Full Publication Checks
Then error RSC-001 is reported 3 times
And no other errors or warnings are reported

Scenario: Report a CSS file declared with an invalid media type and no fallback
When checking EPUB 'package-manifest-css-wrong-media-type-error'
Then error CSS-010 is reported
And no errors or warnings are reported


#### 3.4.4.3 Manifest Fallbacks

Expand Down

0 comments on commit 8d77b0f

Please sign in to comment.