From 5d637fed94654cec217820f726ecfc96e4e171af Mon Sep 17 00:00:00 2001 From: Romain Deltour Date: Mon, 24 Jan 2022 10:06:28 +0100 Subject: [PATCH] feat: check discouraged HTML elements (base, rp, embed) EPUB 3.3 discourages the use of the following elements: - `base` - `rp` - `embed` This commits: - adds a new check HTM-055 to report all uses of discouraged elements - add tests for discouraged constructs - tweak existing tests that used discouraged constructs Fix #1271 --- .../epubcheck/messages/DefaultSeverities.java | 1 + .../adobe/epubcheck/messages/MessageId.java | 1 + .../com/adobe/epubcheck/ops/OPSHandler30.java | 20 ++++++++++++++++++- .../messages/MessageBundle.properties | 1 + .../epub3/content-document-xhtml.feature | 20 +++++++++++++++++++ .../epub3/content-publication.feature | 4 +++- .../discouraged-base-warning.xhtml | 11 ++++++++++ .../discouraged-embed-warning.xhtml | 11 ++++++++++ .../discouraged-rp-warning.xhtml | 11 ++++++++++ .../EPUB/content_001.xhtml | 1 - 10 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 src/test/resources/epub3/files/content-document-xhtml/discouraged-base-warning.xhtml create mode 100644 src/test/resources/epub3/files/content-document-xhtml/discouraged-embed-warning.xhtml create mode 100644 src/test/resources/epub3/files/content-document-xhtml/discouraged-rp-warning.xhtml diff --git a/src/main/java/com/adobe/epubcheck/messages/DefaultSeverities.java b/src/main/java/com/adobe/epubcheck/messages/DefaultSeverities.java index e636de7b7..af871ac41 100644 --- a/src/main/java/com/adobe/epubcheck/messages/DefaultSeverities.java +++ b/src/main/java/com/adobe/epubcheck/messages/DefaultSeverities.java @@ -136,6 +136,7 @@ private void initialize() severities.put(MessageId.HTM_052, Severity.ERROR); severities.put(MessageId.HTM_053, Severity.INFO); severities.put(MessageId.HTM_054, Severity.ERROR); + severities.put(MessageId.HTM_055, Severity.WARNING); // Media severities.put(MessageId.MED_001, Severity.ERROR); diff --git a/src/main/java/com/adobe/epubcheck/messages/MessageId.java b/src/main/java/com/adobe/epubcheck/messages/MessageId.java index 5822f946b..06fb120aa 100644 --- a/src/main/java/com/adobe/epubcheck/messages/MessageId.java +++ b/src/main/java/com/adobe/epubcheck/messages/MessageId.java @@ -130,6 +130,7 @@ public enum MessageId implements Comparable HTM_052("HTM-052"), HTM_053("HTM_053"), HTM_054("HTM_054"), + HTM_055("HTM_055"), // Messages associated with media (images, audio and video) MED_001("MED-001"), diff --git a/src/main/java/com/adobe/epubcheck/ops/OPSHandler30.java b/src/main/java/com/adobe/epubcheck/ops/OPSHandler30.java index 1388bc09d..9b05e2502 100644 --- a/src/main/java/com/adobe/epubcheck/ops/OPSHandler30.java +++ b/src/main/java/com/adobe/epubcheck/ops/OPSHandler30.java @@ -299,11 +299,12 @@ public void startElement() super.startElement(); XMLElement e = parser.getCurrentElement(); - String name = e.getName(); + checkDiscouragedElements(e); processSemantics(e); processSectioning(e); + String name = e.getName(); if (name.equals("html")) { vocabs = VocabUtil.parsePrefixDeclaration( @@ -387,6 +388,23 @@ else if ("http://www.w3.org/2000/svg".equals(e.getNamespace()) && name.equals("t checkSSMLPh(e.getAttributeNS("http://www.w3.org/2001/10/synthesis", "ph")); } + + protected void checkDiscouragedElements(XMLElement elem) + { + if (EpubConstants.HtmlNamespaceUri.equals(elem.getNamespace())) + { + switch (elem.getName()) + { + case "base": + case "embed": + case "rp": + report.message(MessageId.HTM_055, + EPUBLocation.create(path, parser.getLineNumber(), parser.getColumnNumber()), + elem.getName()); + } + + } + } protected void processInlineScripts(com.adobe.epubcheck.xml.XMLElement e) { diff --git a/src/main/resources/com/adobe/epubcheck/messages/MessageBundle.properties b/src/main/resources/com/adobe/epubcheck/messages/MessageBundle.properties index 092f2cb2e..6b7fd61db 100644 --- a/src/main/resources/com/adobe/epubcheck/messages/MessageBundle.properties +++ b/src/main/resources/com/adobe/epubcheck/messages/MessageBundle.properties @@ -123,6 +123,7 @@ HTM_051=Found Microdata semantic enrichments but no RDFa. EDUPUB recommends usin HTM_052=The property "region-based" is only allowed on nav elements in Data Navigation Documents. HTM_053=Found an external file link (file://) in file: "%1$s". HTM_054=Custom attribute namespace ("%1$s") must not include the string "%2$s" in its domain. +HTM_055=The "%1$s" element should not be used (discouraged construct) #media MED_001=Video poster must have core media image type. diff --git a/src/test/resources/epub3/content-document-xhtml.feature b/src/test/resources/epub3/content-document-xhtml.feature index dd5e94033..da51c0296 100644 --- a/src/test/resources/epub3/content-document-xhtml.feature +++ b/src/test/resources/epub3/content-document-xhtml.feature @@ -787,3 +787,23 @@ Feature: EPUB 3 ▸ Content Documents ▸ XHTML Document Checks Scenario: Verify RDF elements can be embedded in SVG When checking document 'svg-rdf-valid.xhtml' Then no errors or warnings are reported + + ## Discouraged Constructs + + Scenario: Report `base` as a discouraged construct + When checking document 'discouraged-base-warning.xhtml' + Then warning HTM-055 is reported + And the message contains 'base' + And no other errors or warnings are reported + + Scenario: Report `embed` as a discouraged construct + When checking document 'discouraged-embed-warning.xhtml' + Then warning HTM-055 is reported + And the message contains 'embed' + And no other errors or warnings are reported + + Scenario: Report `rp` as a discouraged construct + When checking document 'discouraged-rp-warning.xhtml' + Then warning HTM-055 is reported 2 times + And the message contains 'rp' + And no other errors or warnings are reported \ No newline at end of file diff --git a/src/test/resources/epub3/content-publication.feature b/src/test/resources/epub3/content-publication.feature index 2205f3175..fea256794 100644 --- a/src/test/resources/epub3/content-publication.feature +++ b/src/test/resources/epub3/content-publication.feature @@ -37,10 +37,12 @@ Feature: EPUB 3 ▸ Content Documents ▸ Full Publication Checks Scenario: Verify that a base url can be set When checking EPUB 'content-xhtml-base-url-valid' + Then warning HTM-055 is reported (side effect of `base` being discouraged) Then no errors or warnings are reported Scenario: Report relative paths as remote resources when HTML `base` is set to an extenal URL (issue 155) When checking EPUB 'content-xhtml-base-url-remote-relative-path-error' + Then warning HTM-055 is reported (side effect of `base` being discouraged) Then error RSC-006 is reported And no other errors or warnings are reported @@ -213,7 +215,7 @@ Feature: EPUB 3 ▸ Content Documents ▸ Full Publication Checks Scenario: Verify that an SVG image can be referenced from `img`, `object` and `iframe` elements When checking EPUB 'content-xhtml-svg-reference-valid' - Then no errors or warnings are reported + And no errors or warnings are reported Scenario: Verify that `svg:switch` doesn't trigger the package document `switch` property check When checking EPUB 'content-xhtml-svg-switch-valid' diff --git a/src/test/resources/epub3/files/content-document-xhtml/discouraged-base-warning.xhtml b/src/test/resources/epub3/files/content-document-xhtml/discouraged-base-warning.xhtml new file mode 100644 index 000000000..a643f15eb --- /dev/null +++ b/src/test/resources/epub3/files/content-document-xhtml/discouraged-base-warning.xhtml @@ -0,0 +1,11 @@ + + + + + + Test + + +

Test

+ + diff --git a/src/test/resources/epub3/files/content-document-xhtml/discouraged-embed-warning.xhtml b/src/test/resources/epub3/files/content-document-xhtml/discouraged-embed-warning.xhtml new file mode 100644 index 000000000..0e1b07395 --- /dev/null +++ b/src/test/resources/epub3/files/content-document-xhtml/discouraged-embed-warning.xhtml @@ -0,0 +1,11 @@ + + + + + Test + + +

Test

+ + + diff --git a/src/test/resources/epub3/files/content-document-xhtml/discouraged-rp-warning.xhtml b/src/test/resources/epub3/files/content-document-xhtml/discouraged-rp-warning.xhtml new file mode 100644 index 000000000..142f616ef --- /dev/null +++ b/src/test/resources/epub3/files/content-document-xhtml/discouraged-rp-warning.xhtml @@ -0,0 +1,11 @@ + + + + + Test + + +

Test

+ かん + + diff --git a/src/test/resources/epub3/files/epub/content-xhtml-svg-reference-valid/EPUB/content_001.xhtml b/src/test/resources/epub3/files/epub/content-xhtml-svg-reference-valid/EPUB/content_001.xhtml index 9fdd2589c..79857d9d7 100644 --- a/src/test/resources/epub3/files/epub/content-xhtml-svg-reference-valid/EPUB/content_001.xhtml +++ b/src/test/resources/epub3/files/epub/content-xhtml-svg-reference-valid/EPUB/content_001.xhtml @@ -5,7 +5,6 @@ Minimal EPUB - test