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: re-implement relevant checks from the ctc package in core handlers #1394

Merged
merged 4 commits into from
Dec 5, 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 @@ -324,7 +324,7 @@ private void initialize()
severities.put(MessageId.RSC_015, Severity.ERROR);
severities.put(MessageId.RSC_016, Severity.FATAL);
severities.put(MessageId.RSC_017, Severity.WARNING);
severities.put(MessageId.RSC_018, Severity.WARNING);
severities.put(MessageId.RSC_018, Severity.SUPPRESSED); // Reported as RSC-007
severities.put(MessageId.RSC_019, Severity.WARNING);
severities.put(MessageId.RSC_020, Severity.ERROR);
severities.put(MessageId.RSC_021, Severity.ERROR);
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/adobe/epubcheck/ops/OPSHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ else if (".".equals(href))
}
}
}
if ("file".equals(uri.getScheme())) {
report.message(MessageId.HTM_053, parser.getLocation(), uri);
}

/*
* mgy 20120417 adding check for base to initial if clause as part of
Expand Down
68 changes: 68 additions & 0 deletions src/main/java/com/adobe/epubcheck/ops/OPSHandler30.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -43,6 +44,7 @@
import com.adobe.epubcheck.xml.XMLElement;
import com.adobe.epubcheck.xml.XMLParser;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
Expand All @@ -63,6 +65,8 @@ public class OPSHandler30 extends OPSHandler
private static Map<String, Vocab> KNOWN_VOCAB_URIS = ImmutableMap.of(MagazineNavigationVocab.URI,
MagazineNavigationVocab.VOCAB, ForeignVocabs.PRISM_URI, ForeignVocabs.PRISM_VOCAB);
private static Set<String> DEFAULT_VOCAB_URIS = ImmutableSet.of(StructureVocab.URI);

private static final Splitter TOKENIZER = Splitter.onPattern("\\s+").omitEmptyStrings();

private Map<String, Vocab> vocabs = RESERVED_VOCABS;

Expand All @@ -87,6 +91,7 @@ public class OPSHandler30 extends OPSHandler
protected boolean isOutermostSVGAlreadyProcessed = false;
protected boolean hasAltorAnnotation = false;
protected boolean hasTitle = false;
protected boolean hasViewport = false;

static protected final String[] scriptEventsStrings = { "onafterprint", "onbeforeprint",
"onbeforeunload", "onerror", "onhaschange", "onload", "onmessage", "onoffline", "onpagehide",
Expand Down Expand Up @@ -312,6 +317,9 @@ public void startElement()
KNOWN_VOCAB_URIS, DEFAULT_VOCAB_URIS, report,
EPUBLocation.create(path, parser.getLineNumber(), parser.getColumnNumber()));
}
else if (EpubConstants.HtmlNamespaceUri.equals(e.getNamespace()) && name.equals("meta")) {
processMeta(e);
}
else if (name.equals("link"))
{
processLink(e);
Expand All @@ -325,6 +333,11 @@ else if (name.equals("math"))
requiredProperties.add(ITEM_PROPERTIES.MATHML);
inMathML = true;
hasAltorAnnotation = (null != e.getAttribute("alttext"));
String altimg = e.getAttribute("altimg");
if (altimg != null) {
super.checkImage(e, null, "altimg");
}

}
else if (name.equals("svg"))
{
Expand Down Expand Up @@ -679,6 +692,31 @@ else if (!isOutermostSVGAlreadyProcessed)
}
}

protected void processMeta(XMLElement e)
{
if (EpubConstants.HtmlNamespaceUri.equals(e.getNamespace()))
{
String name = e.getAttribute("name");
if ("viewport".equals(name))
{
hasViewport = true;
// For a fixed-layout document:
// check that the vieport declares both height and width
if (context.opfItem.isPresent() && context.opfItem.get().isFixedLayout())
{
String contentAttribute = e.getAttribute("content");
if (contentAttribute == null || !contentAttribute.contains("width=")
|| !contentAttribute.contains("height="))
rdeltour marked this conversation as resolved.
Show resolved Hide resolved
{
report.message(MessageId.HTM_047,
EPUBLocation.create(path, parser.getLineNumber(), parser.getColumnNumber()));
}
}
}
}
}


protected void processTable(XMLElement e)
{
context.featureReport.report(FeatureEnum.TABLE, parser.getLocation());
Expand Down Expand Up @@ -802,6 +840,9 @@ else if (name.equals("svg"))
{
inSvg = false;
}
else if (EpubConstants.HtmlNamespaceUri.equals(e.getNamespace()) && name.equals("head")) {
checkHead();
}
}

/*
Expand Down Expand Up @@ -859,4 +900,31 @@ protected void checkProperties()
.join(PackageVocabs.ITEM_VOCAB.getNames(uncheckedProperties)));
}
}

protected void checkHead()
{
if (context.opfItem.isPresent() && context.opfItem.get().isFixedLayout() && !hasViewport)
{
report.message(MessageId.HTM_046,
EPUBLocation.create(path, parser.getLineNumber(), parser.getColumnNumber()));
}
}

@Override
protected void checkLink(XMLElement e, String attrNS, String attr)
{
super.checkLink(e, attrNS, attr);
String rel = e.getAttributeNS(attrNS, "rel");
if (rel != null)
{
String title = e.getAttributeNS(attrNS, "title");
List<String> linkTypes = TOKENIZER.splitToList(rel);
if (linkTypes.contains("alternate") && linkTypes.contains("stylesheet")
&& Strings.isNullOrEmpty(title))
{
report.message(MessageId.CSS_015,
EPUBLocation.create(path, parser.getLineNumber(), parser.getColumnNumber()));
}
}
}
}
5 changes: 5 additions & 0 deletions src/test/resources/epub3/content-document-xhtml.feature
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,11 @@ Feature: EPUB 3 ▸ Content Documents ▸ XHTML Document Checks
When checking document 'link-rel-stylesheet-alternate-valid.xhtml'
Then no errors or warnings are reported

Scenario: Report `link` element defining an alternative stylesheet with no title
When checking document 'link-rel-stylesheet-alternate-no-title-error.xhtml'
Then error CSS-015 is reported 2 times (one for a missing title, one for an empty title)
And no other errors or warnings are reported


#### Lists

Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/epub3/content-publication.feature
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ Feature: EPUB 3 ▸ Content Documents ▸ Full Publication Checks

Scenario: Report a MathML formula with an alternative image that cannot be found
When checking EPUB 'content-xhtml-mathml-altimg-not-found-warning'
Then warning RSC-018 is reported
Then error RSC-007 is reported
And no other errors or warnings are reported


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta charset="utf-8" />
<title>Test</title>
<link href="tite-empty.css" rel="alternate stylesheet" type="text/css" title="" />
<link href="title-missing.css" rel="alternate stylesheet" type="text/css" />
</head>
<body>
<h1>Test</h1>
</body>
</html>