Skip to content

Commit

Permalink
fix: allow unknown alternate style sheet class names
Browse files Browse the repository at this point in the history
A class name found on a `link` element representing a style sheet was
reported as an error when it was not one of the known keyword defined
in [EPUB Alternate Style Tags](https://idpf.org/epub/altss-tags/).

This commit fixes that by allowing any name in the class attribute.

This commit also downgrades `CSS-005` to a usage; it is reported when
two mutually-exclusive class names are used on the same link element.
EPUB Alternate Style Tags defines these as mutual exclusive names, but
it is mostly unimplemeneted and this was never strictly forbidden.

Fix #989
  • Loading branch information
rdeltour committed Dec 30, 2022
1 parent 959868d commit 6651013
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private void initialize()
severities.put(MessageId.CSS_002, Severity.ERROR);
severities.put(MessageId.CSS_003, Severity.WARNING);
severities.put(MessageId.CSS_004, Severity.ERROR);
severities.put(MessageId.CSS_005, Severity.ERROR);
severities.put(MessageId.CSS_005, Severity.USAGE);
severities.put(MessageId.CSS_006, Severity.USAGE);
severities.put(MessageId.CSS_007, Severity.INFO);
severities.put(MessageId.CSS_008, Severity.ERROR);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/adobe/epubcheck/ops/OPSHandler30.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import com.adobe.epubcheck.vocab.StagingEdupubVocab;
import com.adobe.epubcheck.vocab.StructureVocab;
import com.adobe.epubcheck.vocab.StructureVocab.EPUB_TYPES;
import com.adobe.epubcheck.vocab.UncheckedVocab;
import com.adobe.epubcheck.vocab.Vocab;
import com.adobe.epubcheck.vocab.VocabUtil;
import com.adobe.epubcheck.xml.model.XMLAttribute;
Expand All @@ -69,7 +70,7 @@ public class OPSHandler30 extends OPSHandler
MagazineNavigationVocab.PREFIX, MagazineNavigationVocab.VOCAB, ForeignVocabs.PRISM_PREFIX,
ForeignVocabs.PRISM_VOCAB);
private static Map<String, Vocab> ALTCSS_VOCABS = ImmutableMap.<String, Vocab> of("",
AltStylesheetVocab.VOCAB);
AggregateVocab.of(AltStylesheetVocab.VOCAB, new UncheckedVocab("", "")));
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ CSS_001=The "%1$s" property must not be included in an EPUB Style Sheet.
CSS_002=Empty or NULL reference found.
CSS_003=CSS document is encoded in UTF-16. It should be encoded in UTF-8 instead.
CSS_004=CSS documents must be encoded in UTF-8, detected %1%s;
CSS_005=Conflicting alternate style attributes found: %1$s.
CSS_005=Conflicting alternate style tags found: %1$s.
CSS_006=CSS selector specifies fixed position.
CSS_007=Font-face reference "%1$s" refers to non-standard font type "%2$s".
CSS_008=An error occurred while parsing the CSS: %1$s.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,14 +367,23 @@ Feature: EPUB 3 — Content Documents — XHTML
#### Links

Scenario: Verify a `link` element with a known alt style tag
When checking document 'link-alt-style-tags-valid.xhtml'
Given the reporting level is set to usage
When checking document 'link-alt-style-tags-known-valid.xhtml'
Then no usages are reported
And no errors or warnings are reported

Scenario: Report a `link` element with an unknown alt style tag
Given the reporting level is set to usage
When checking document 'link-alt-style-tags-unknown-valid.xhtml'
Then no errors or warnings are reported
And no usages are reported

Scenario: Report a `link` element with an unknown alt style tag
When checking document 'link-alt-style-tags-error.xhtml'
Then error OPF-027 is reported
And error CSS-005 is reported
And no other errors or warnings are reported
Given the reporting level is set to usage
When checking document 'link-alt-style-tags-conflict-usage.xhtml'
Then no errors or warnings are reported
And usage CSS-005 is reported
But no other usages are reported

Scenario: Verify `link` elements used to declare alternative stylesheets
When checking document 'link-rel-stylesheet-alternate-valid.xhtml'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta charset="utf-8" />
<title>alt style tag css declaration</title>
<link rel="stylesheet" href="horizontal.css" class="day night" />
</head>
<body></body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta charset="utf-8" />
<title>invalid alt style tag css declaration</title>
<link rel="stylesheet" href="horizontal.css" class="horizontal invalid vertical" />
<title>unknown alt style tag css declaration</title>
<link rel="stylesheet" href="horizontal.css" class="unknown" />
</head>
<body> </body>
</html>

0 comments on commit 6651013

Please sign in to comment.