Skip to content

Commit cf16167

Browse files
authored
feat: report unusual 'epub' namespace (usage) (#1624)
Report a USAGE message when a namespace other than the usual `http://www.idpf.org/2007/ops` URL is associated to the `epub` prefix in XHTML content documents. This is reported as HTM_010 (thereby repurposing this unused message ID). This is only reported as a USAGE, since the spec does not strictly requires that the `epub` prefix is tied to the well-known URL. But it can help catch typos as reported in #1601. Fixes #1601
1 parent 1c6131b commit cf16167

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

src/main/java/com/adobe/epubcheck/ops/OPSHandler30.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.w3c.epubcheck.util.microsyntax.ViewportMeta;
2121
import org.w3c.epubcheck.util.microsyntax.ViewportMeta.ParseError;
2222
import org.w3c.epubcheck.util.url.URLUtils;
23+
import org.xml.sax.SAXException;
2324

2425
import com.adobe.epubcheck.api.EPUBLocation;
2526
import com.adobe.epubcheck.api.EPUBProfile;
@@ -49,6 +50,7 @@
4950
import com.adobe.epubcheck.vocab.UncheckedVocab;
5051
import com.adobe.epubcheck.vocab.Vocab;
5152
import com.adobe.epubcheck.vocab.VocabUtil;
53+
import com.adobe.epubcheck.xml.Namespaces;
5254
import com.adobe.epubcheck.xml.model.XMLAttribute;
5355
import com.adobe.epubcheck.xml.model.XMLElement;
5456
import com.google.common.base.Joiner;
@@ -1106,4 +1108,14 @@ protected void checkLink()
11061108
}
11071109
}
11081110

1111+
@Override
1112+
public void startPrefixMapping(String prefix, String uri)
1113+
throws SAXException
1114+
{
1115+
super.startPrefixMapping(prefix, uri);
1116+
if ("epub".equals(prefix) && !(Namespaces.OPS.equals(uri))) {
1117+
report.message(MessageId.HTM_010, location(), uri);
1118+
}
1119+
}
1120+
11091121
}

src/main/resources/com/adobe/epubcheck/messages/MessageBundle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ HTM_004=Irregular DOCTYPE: found "%1$s", expected "%2$s".
4545
HTM_005=An external reference was found.
4646
HTM_007=Empty or whitespace-only value of attribute ssml:ph.
4747
HTM_009=The DOCTYPE provided is obsolete or irregular and can be removed.
48-
HTM_010=Namespace uri "%1$s" was found.
48+
HTM_010=Namespace "%1$s" is unusual for the prefix "epub".
4949
HTM_011=Entity is undeclared.
5050
HTM_011_SUG=Define the entity or use the numbered entity instead.
5151
HTM_025=Non-registered URI scheme type found in href.

src/test/resources/epub3/06-content-document/content-document-xhtml.feature

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,3 +1010,11 @@ Feature: EPUB 3 — Content Documents — XHTML
10101010
And the message contains 'rp'
10111011
And no other errors or warnings are reported
10121012

1013+
#### Other
1014+
1015+
Scenario: Report an unrecognized `epub` namespace (informative)
1016+
Given the reporting level is set to usage
1017+
When checking document 'ns-epub-unknown-info.xhtml'
1018+
Then usage HTM-010 is reported
1019+
And the message contains 'Namespace "http://http://www.idpf.org/2007/ops" is unusual'
1020+
And no errors or warnings are reported
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://http://www.idpf.org/2007/ops"
3+
xml:lang="en" lang="en">
4+
<head>
5+
<meta charset="utf-8" />
6+
<title>Test</title>
7+
</head>
8+
<body>
9+
<h1>Test</h1>
10+
</body>
11+
</html>

0 commit comments

Comments
 (0)