diff --git a/src/main/java/com/adobe/epubcheck/messages/DefaultSeverities.java b/src/main/java/com/adobe/epubcheck/messages/DefaultSeverities.java index dd8637956..f00a64328 100644 --- a/src/main/java/com/adobe/epubcheck/messages/DefaultSeverities.java +++ b/src/main/java/com/adobe/epubcheck/messages/DefaultSeverities.java @@ -135,6 +135,7 @@ private void initialize() severities.put(MessageId.HTM_051, Severity.WARNING); severities.put(MessageId.HTM_052, Severity.ERROR); severities.put(MessageId.HTM_053, Severity.INFO); + severities.put(MessageId.HTM_054, Severity.ERROR); // 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 aa5cc1bcf..92fbaa60a 100644 --- a/src/main/java/com/adobe/epubcheck/messages/MessageId.java +++ b/src/main/java/com/adobe/epubcheck/messages/MessageId.java @@ -129,6 +129,7 @@ public enum MessageId implements Comparable HTM_051("HTM-051"), HTM_052("HTM-052"), HTM_053("HTM_053"), + HTM_054("HTM_054"), // Messages associated with media (images, audio and video) MED_001("MED-001"), diff --git a/src/main/java/com/adobe/epubcheck/xml/XMLParser.java b/src/main/java/com/adobe/epubcheck/xml/XMLParser.java index a752640fa..4d85d7c93 100755 --- a/src/main/java/com/adobe/epubcheck/xml/XMLParser.java +++ b/src/main/java/com/adobe/epubcheck/xml/XMLParser.java @@ -28,6 +28,8 @@ import java.io.IOException; import java.io.InputStream; import java.io.StringReader; +import java.net.URI; +import java.net.URISyntaxException; import java.util.HashSet; import java.util.Hashtable; import java.util.Locale; @@ -581,6 +583,7 @@ private Attributes preprocessAttributes(String elemNamespace, String elemName, S { if (context.version == EPUBVersion.VERSION_3) { + String attrNamespace = attributes.getURI(i); // Remove data-* attributes in both XHTML and SVG if (isDataAttribute(attributes, i)) { @@ -588,8 +591,12 @@ private Attributes preprocessAttributes(String elemNamespace, String elemName, S } // Remove custom namespace attributes in XHTML else if ("application/xhtml+xml".equals(context.mimeType) - && isHTMLCustomNamespace(attributes.getURI(i))) + && isHTMLCustomNamespace(attrNamespace)) { + String reserved = findReservedStringInHTMLCustomNamespace(attrNamespace); + if (reserved != null) { + report.message(MessageId.HTM_054, getLocation(), attrNamespace, reserved); + } attributes.removeAttribute(i); } // Normalize case of case-insensitive attributes in XHTML @@ -624,6 +631,22 @@ private static boolean isHTMLCustomNamespace(String namespace) return !KNOWN_XHTML_NAMESPACES.contains(namespace.trim()); } + private static String findReservedStringInHTMLCustomNamespace(String namespace) + { + if (namespace != null) { + try + { + URI uri = new URI(namespace); + if (uri.getHost().contains("w3.org")) return "w3.org"; + if (uri.getHost().contains("idpf.org")) return "idpf.org"; + } catch (URISyntaxException e) + { + // ignore + } + } + return null; + } + private static boolean isCaseInsensitiveAttribute(Attributes attributes, int index) { return (attributes.getURI(index).isEmpty() diff --git a/src/main/resources/com/adobe/epubcheck/messages/MessageBundle.properties b/src/main/resources/com/adobe/epubcheck/messages/MessageBundle.properties index 9c1ba79f7..9a7e4cfaf 100644 --- a/src/main/resources/com/adobe/epubcheck/messages/MessageBundle.properties +++ b/src/main/resources/com/adobe/epubcheck/messages/MessageBundle.properties @@ -122,6 +122,7 @@ HTM_050=Found epub:type="pagebreak" attribute in content document. HTM_051=Found Microdata semantic enrichments but no RDFa. EDUPUB recommends using RDFa Lite. 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. #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 9b85bd390..dd5e94033 100644 --- a/src/test/resources/epub3/content-document-xhtml.feature +++ b/src/test/resources/epub3/content-document-xhtml.feature @@ -615,7 +615,11 @@ Feature: EPUB 3 ▸ Content Documents ▸ XHTML Document Checks Scenario: Verify attributes in custom namespaces are ignored When checking document 'attrs-custom-ns-valid.xhtml' Then no errors or warnings are reported - + + Scenario: Report custom attributes using reserved strings in their namespace + When checking document 'attrs-custom-ns-reserved-error.xhtml' + Then error HTM-054 is reported 2 times + And no other errors or warnings are reported ## 2.5 HTML Deviations and Constraints diff --git a/src/test/resources/epub3/files/content-document-xhtml/attrs-custom-ns-reserved-error.xhtml b/src/test/resources/epub3/files/content-document-xhtml/attrs-custom-ns-reserved-error.xhtml new file mode 100644 index 000000000..07032034e --- /dev/null +++ b/src/test/resources/epub3/files/content-document-xhtml/attrs-custom-ns-reserved-error.xhtml @@ -0,0 +1,12 @@ + + + + + Test + + +

Test

+ + diff --git a/src/test/resources/epub3/files/content-document-xhtml/attrs-custom-ns-valid.xhtml b/src/test/resources/epub3/files/content-document-xhtml/attrs-custom-ns-valid.xhtml index 7e2a9888c..5f1c393a9 100644 --- a/src/test/resources/epub3/files/content-document-xhtml/attrs-custom-ns-valid.xhtml +++ b/src/test/resources/epub3/files/content-document-xhtml/attrs-custom-ns-valid.xhtml @@ -1,11 +1,10 @@ - - + + - - Attributes in custom namespace + + Test - +

Test

-

custom attribute!