Skip to content

Commit 8631b7d

Browse files
committed
feat: restrict SVG title element to HTML elements
This commit updates the content model of the SVG title element to allow any text or HTML elements, but reject any non-HTML element. - use NVDL to reject non-HTML namespaces - the master XHTML schema is now the NVDL schema - add an element class to include all HTML elements Fix #1342
1 parent 3086258 commit 8631b7d

26 files changed

+224
-107
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public class OPSChecker extends PublicationResourceChecker
5656
.putAll(Predicates.and(mimetype("application/xhtml+xml"), version(EPUBVersion.VERSION_2)),
5757
XMLValidators.XHTML_20_NVDL, XMLValidators.XHTML_20_SCH, XMLValidators.IDUNIQUE_20_SCH)
5858
.putAll(Predicates.and(mimetype("application/xhtml+xml"), version(EPUBVersion.VERSION_3)),
59-
XMLValidators.XHTML_30_RNC, XMLValidators.XHTML_30_SCH, XMLValidators.SVG_INFORMATIVE_30_NVDL)
59+
XMLValidators.XHTML_30_NVDL, XMLValidators.SVG_INFORMATIVE_30_NVDL)
6060
.putAll(Predicates.and(mimetype("image/svg+xml"), version(EPUBVersion.VERSION_2)),
6161
XMLValidators.SVG_20_NVDL, XMLValidators.IDUNIQUE_20_SCH)
6262
.putAll(Predicates.and(mimetype("image/svg+xml"), version(EPUBVersion.VERSION_3)),

src/main/java/com/adobe/epubcheck/xml/XMLValidators.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public enum XMLValidators
4545
XHTML_20_SCH("schema/20/sch/xhtml.sch"),
4646
XHTML_30_SCH("schema/30/epub-xhtml-30.sch"),
4747
XHTML_30_RNC("schema/30/epub-xhtml-30.rnc"),
48+
XHTML_30_NVDL("schema/30/epub-xhtml-30.nvdl"),
4849
XHTML_EDUPUB_STRUCTURE_SCH("schema/30/edupub/edu-structure.sch"),
4950
XHTML_EDUPUB_SEMANTICS_SCH("schema/30/edupub/edu-semantics.sch"),
5051
XHTML_DATANAV_SCH("schema/30/datanav/datanav-xhtml.sch"),

src/main/resources/com/adobe/epubcheck/schema/30/epub-svg-30.nvdl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<validate schema="epub-svg-30.rnc" schemaType="application/relax-ng-compact-syntax"
66
useMode="allowForeignNS">
77
<context path="foreignObject" useMode="attachAnyNS"/>
8+
<context path="title" useMode="allowOnlyHTML"/>
89
</validate>
910
<validate schema="epub-svg-30.sch" useMode="attachAnyNS"/>
1011
</namespace>
@@ -34,4 +35,27 @@
3435
<attach/>
3536
</anyNamespace>
3637
</mode>
38+
<mode name="allowOnlyHTML">
39+
<namespace ns="http://www.w3.org/1999/xhtml">
40+
<attach/>
41+
</namespace>
42+
<namespace ns="http://www.idpf.org/2007/ops" match="attributes">
43+
<attach/>
44+
</namespace>
45+
<namespace ns="http://www.w3.org/1999/xlink" match="attributes">
46+
<attach/>
47+
</namespace>
48+
<namespace ns="http://www.w3.org/XML/1998/namespace" match="attributes">
49+
<attach/>
50+
</namespace>
51+
<namespace ns="" match="attributes">
52+
<attach/>
53+
</namespace>
54+
<anyNamespace match="attributes">
55+
<allow/>
56+
</anyNamespace>
57+
<anyNamespace>
58+
<reject/>
59+
</anyNamespace>
60+
</mode>
3761
</rules>
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
namespace svg = "http://www.w3.org/2000/svg"
22

3-
include "./mod/epub-xhtml.rnc" {
3+
include "./mod/epub-xhtml-inc.rnc" {
44
start = svg
55
}
66
include "./mod/epub-mathml3.rnc"
77
include "./mod/epub-svg-inc.rnc"
88

9-
svg.title.content |= common.elem.phrasing
9+
svg.title.content |= common.inner.anyhtml
1010

1111
svg.foreignObject.content |=
1212
( body.elem
1313
| common.inner.flow
1414
| math
1515
)
1616

17-
mtext.content |= common.elem.phrasing
17+
mtext.content |= common.elem.phrasing

src/main/resources/com/adobe/epubcheck/schema/30/epub-svg-informative.rnc

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,5 @@ SVG.Core.attrib &= aria.global?
1717
SVG.Core.extra.attrib &= epub.type.attr?
1818

1919
## Do not check restricted elements, they are checked in normative schemas
20-
SVG.foreignObject.content |= any.content
21-
SVG.title.content |= any.content
22-
23-
## Anything
24-
25-
## Any attribute from any namespace, other than the special cases
26-
any.attr = attribute * { text }*
27-
## Any element from any namespace, other than the special cases
28-
any.elem = element * { any.content & any.attr }
29-
## Any content from any namespace
30-
any.content = text & any.elem*
20+
SVG.foreignObject.content |= common.inner.anything
21+
SVG.title.content |= common.inner.anything
Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,46 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<rules xmlns="http://purl.oclc.org/dsdl/nvdl/ns/structure/1.0" startMode="html">
2+
<rules xmlns="http://purl.oclc.org/dsdl/nvdl/ns/structure/1.0"
3+
xmlns:svg="http://www.w3.org/2000/svg" startMode="html">
34
<mode name="html">
45
<namespace ns="http://www.w3.org/1999/xhtml">
56
<validate schema="epub-xhtml-30.rnc" schemaType="application/relax-ng-compact-syntax"
6-
useMode="attach"/>
7+
useMode="attach">
8+
<context path="title" useMode="allowOnlyHTML"/>
9+
</validate>
710
<validate schema="epub-xhtml-30.sch" useMode="attach"/>
811
</namespace>
912
</mode>
1013
<mode name="attach">
14+
<namespace ns="http://www.w3.org/2000/svg">
15+
<attach>
16+
<context path="title" useMode="allowOnlyHTML"/>
17+
</attach>
18+
</namespace>
1119
<anyNamespace>
1220
<attach/>
1321
</anyNamespace>
1422
</mode>
23+
<mode name="allowOnlyHTML">
24+
<namespace ns="http://www.w3.org/1999/xhtml">
25+
<attach/>
26+
</namespace>
27+
<namespace ns="http://www.idpf.org/2007/ops" match="attributes">
28+
<attach/>
29+
</namespace>
30+
<namespace ns="http://www.w3.org/1999/xlink" match="attributes">
31+
<attach/>
32+
</namespace>
33+
<namespace ns="http://www.w3.org/XML/1998/namespace" match="attributes">
34+
<attach/>
35+
</namespace>
36+
<namespace ns="" match="attributes">
37+
<attach/>
38+
</namespace>
39+
<anyNamespace match="attributes">
40+
<allow/>
41+
</anyNamespace>
42+
<anyNamespace>
43+
<reject/>
44+
</anyNamespace>
45+
</mode>
1546
</rules>

src/main/resources/com/adobe/epubcheck/schema/30/epub-xhtml-30.rnc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace svg = "http://www.w3.org/2000/svg"
22

3-
include "./mod/epub-xhtml.rnc"
3+
include "./mod/epub-xhtml-inc.rnc"
44
include "./mod/epub-mathml3.rnc"
55
include "./mod/epub-svg-inc.rnc" {
66
svg.attr.id = attribute id { datatype.html5.token }?
@@ -11,7 +11,7 @@ common.elem.phrasing |= math
1111

1212
math.attributes &= aria.global?
1313

14-
svg.title.content |= common.elem.phrasing
14+
svg.title.content |= common.inner.anyhtml
1515

1616
svg.foreignObject.content |=
1717
( common.inner.flow

src/main/resources/com/adobe/epubcheck/schema/30/epub-xhtml-30.sch

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,6 @@
152152
<param name="descendant" value="h:label"/>
153153
</pattern>
154154

155-
<pattern id="descendant-svgtitle-svg" is-a="disallowed-descendants">
156-
<param name="ancestor" value="svg:title"/>
157-
<param name="descendant" value="svg:*"/>
158-
</pattern>
159-
160155
<pattern id="bdo-dir" is-a="required-attr">
161156
<param name="elem" value="h:bdo"/>
162157
<param name="attr" value="dir"/>

src/main/resources/com/adobe/epubcheck/schema/30/mod/epub-svg-inc.rnc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ svg.foreignObject.content = notAllowed
2727
### SVG title element restrictions
2828
svg.title =
2929
element title { any.attr & svg.title.content }
30-
svg.title.content = text
30+
svg.title.content = text
3131

3232
## Anything
3333

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
# #####################################################################
3+
## RELAX NG Schema for EPUB HTML 5: For inclusion in master schema #
4+
# #####################################################################
5+
6+
## Include the main XHTML schema
7+
8+
include "./epub-xhtml.rnc"
9+
10+
## HTML fragments
11+
12+
# Note: the default HMTL schema does not define such a category, so we
13+
# do our best to include what makes sense here
14+
15+
common.inner.anyhtml =
16+
html.elem
17+
| body.elem
18+
| common.inner.flow

0 commit comments

Comments
 (0)