From ddb36767a5002f3e4d25f9f4b93e61a7deb5f4e3 Mon Sep 17 00:00:00 2001 From: Romain Deltour Date: Sun, 22 Dec 2024 00:50:15 +0100 Subject: [PATCH] fix: reject unknown `epub:` attributes in SVG The spec only requires SVG to be well-formed, but one can argue that attributes in the EPUB namespace can only be defined by the EPUB specs and therefore should still be validated. For instance, EPUB already specifies where `epub:type` is allowed in SVG, as a normative statement. This commit updates the persmissive SVG schema to reject all attributes in the `http://www.idpf.org/2007/ops` namespace except the known ones. --- .../epubcheck/schema/30/mod/epub-svg-forgiving-inc.rnc | 6 ++++-- .../epub3/06-content-document/content-document-svg.feature | 7 +++++++ .../files/unknown-epub-attribute-error.svg | 7 +++++++ 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 src/test/resources/epub3/06-content-document/files/unknown-epub-attribute-error.svg 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 c08a94acc..94b714f77 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,7 +19,9 @@ svg = element svg { svg.inner & svg.attrs } svg.attrs = - ( svg.epubtype.allowed.attrs ) + ( svg.epubtype.allowed.attrs + & epub.prefix.attr.ns? + ) svg.inner = ( svg.any.inner ) @@ -35,7 +37,7 @@ svg.generic.attr = attribute * - ( id - | epub:type + | epub:* ) { text } # Attribute list of elements where `epub:type` is allowed diff --git a/src/test/resources/epub3/06-content-document/content-document-svg.feature b/src/test/resources/epub3/06-content-document/content-document-svg.feature index 413677a93..20f65df46 100644 --- a/src/test/resources/epub3/06-content-document/content-document-svg.feature +++ b/src/test/resources/epub3/06-content-document/content-document-svg.feature @@ -51,6 +51,13 @@ Feature: EPUB 3 — Content Documents — SVG And the message contains '"epub:type" not allowed' And no other errors or warnings are reported + Scenario: Report an unknown `epub:*` attribute used in SVG + Given the reporting level is set to usage + When checking document 'unknown-epub-attribute-error.svg' + Then error RSC-005 is reported + And the message contains '"epub:unknown" not allowed' + And no other errors or warnings are reported + ### 6.2.2 SVG requirements diff --git a/src/test/resources/epub3/06-content-document/files/unknown-epub-attribute-error.svg b/src/test/resources/epub3/06-content-document/files/unknown-epub-attribute-error.svg new file mode 100644 index 000000000..aee630744 --- /dev/null +++ b/src/test/resources/epub3/06-content-document/files/unknown-epub-attribute-error.svg @@ -0,0 +1,7 @@ + + + Test + Description + +