From 623f5ad8c9e5d72e6ddd5ffa17990be30010439e Mon Sep 17 00:00:00 2001 From: Romain Deltour Date: Sun, 22 Dec 2024 01:47:28 +0100 Subject: [PATCH] fix: disallow `epub:prefix` on embedded SVG Fix #1535 --- .../adobe/epubcheck/schema/30/epub-svg-30.rnc | 3 +++ .../schema/30/mod/epub-svg-forgiving-inc.rnc | 4 +--- .../files/prefix-attribute-on-svg-error.xhtml | 17 +++++++++++++++++ .../epub3/D-vocabularies/vocabularies.feature | 9 +++++++++ 4 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 src/test/resources/epub3/D-vocabularies/files/prefix-attribute-on-svg-error.xhtml diff --git a/src/main/resources/com/adobe/epubcheck/schema/30/epub-svg-30.rnc b/src/main/resources/com/adobe/epubcheck/schema/30/epub-svg-30.rnc index f38bac082..5332da76f 100644 --- a/src/main/resources/com/adobe/epubcheck/schema/30/epub-svg-30.rnc +++ b/src/main/resources/com/adobe/epubcheck/schema/30/epub-svg-30.rnc @@ -12,3 +12,6 @@ include "./mod/epub-xhtml-svg-mathml.rnc" { # Allow `body` element as a child of `foreignObject` svg.foreignObject.inner |= body.elem + +# Allow `epub:prefix` attribute on `svg` root +svg.attrs &= epub.prefix.attr.ns? diff --git a/src/main/resources/com/adobe/epubcheck/schema/30/mod/epub-svg-forgiving-inc.rnc b/src/main/resources/com/adobe/epubcheck/schema/30/mod/epub-svg-forgiving-inc.rnc index 94b714f77..bda634600 100644 --- a/src/main/resources/com/adobe/epubcheck/schema/30/mod/epub-svg-forgiving-inc.rnc +++ b/src/main/resources/com/adobe/epubcheck/schema/30/mod/epub-svg-forgiving-inc.rnc @@ -19,9 +19,7 @@ svg = element svg { svg.inner & svg.attrs } svg.attrs = - ( svg.epubtype.allowed.attrs - & epub.prefix.attr.ns? - ) + ( svg.epubtype.allowed.attrs ) svg.inner = ( svg.any.inner ) diff --git a/src/test/resources/epub3/D-vocabularies/files/prefix-attribute-on-svg-error.xhtml b/src/test/resources/epub3/D-vocabularies/files/prefix-attribute-on-svg-error.xhtml new file mode 100644 index 000000000..20e0e45fd --- /dev/null +++ b/src/test/resources/epub3/D-vocabularies/files/prefix-attribute-on-svg-error.xhtml @@ -0,0 +1,17 @@ + + + + + Test + + +

Loomings

+

Call me Ishmael.

+ + SVG + Description + + + + diff --git a/src/test/resources/epub3/D-vocabularies/vocabularies.feature b/src/test/resources/epub3/D-vocabularies/vocabularies.feature index 4ac435531..444427468 100644 --- a/src/test/resources/epub3/D-vocabularies/vocabularies.feature +++ b/src/test/resources/epub3/D-vocabularies/vocabularies.feature @@ -106,6 +106,8 @@ Feature: EPUB 3 — Vocabularies — Vocabulary association Rule: EPUB creators MUST only specify the `prefix` attribute on the root element of the respective format. + Note that for SVG embedded by inclusion, prefixes MUST be declared on the root html element. + @spec @xref:sec-prefix-attr Example: Report a `prefix` attribute on an XHTML `head` element When checking file 'prefix-attribute-on-head-error.xhtml' @@ -113,6 +115,13 @@ Feature: EPUB 3 — Vocabularies — Vocabulary association And the message contains 'attribute "epub:prefix" not allowed here' And no other errors or warnings are reported + @spec @xref:sec-prefix-attr + Example: Report a `prefix` attribute on an XHTML embedded `svg` element + When checking file 'prefix-attribute-on-svg-error.xhtml' + Then error RSC-005 is reported + And the message contains 'attribute "epub:prefix" not allowed here' + And no other errors or warnings are reported + Rule: EPUB creators MUST NOT declare the prefix '_'.