Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: disallow epub:prefix on embedded SVG #1583

Merged
merged 5 commits into from
Dec 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ private void initialize()
severities.put(MessageId.OPF_007, Severity.WARNING);
severities.put(MessageId.OPF_007a, Severity.ERROR);
severities.put(MessageId.OPF_007b, Severity.ERROR);
severities.put(MessageId.OPF_007c, Severity.ERROR);
severities.put(MessageId.OPF_008, Severity.SUPPRESSED);
severities.put(MessageId.OPF_009, Severity.SUPPRESSED);
severities.put(MessageId.OPF_010, Severity.ERROR);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/adobe/epubcheck/messages/MessageId.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ public enum MessageId implements Comparable<MessageId>
OPF_007("OPF-007"),
OPF_007a("OPF-007a"),
OPF_007b("OPF-007b"),
OPF_007c("OPF-007c"),
OPF_008("OPF-008"),
OPF_009("OPF-009"),
OPF_010("OPF-010"),
Expand Down
34 changes: 19 additions & 15 deletions src/main/java/com/adobe/epubcheck/vocab/VocabUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ private enum EMPTY
* Parses a single property value and report validation errors on the fly.
*
* @param value
* the value to parse.
* the value to parse.
* @param vocabs
* a map of prefix to vocabularies.
* a map of prefix to vocabularies.
* @param context
* the validation context (report, locale, path, etc).
* the validation context (report, locale, path, etc).
* @param location
* the location in the validated file.
* the location in the validated file.
* @return an {@link Optional} containing the property if it was parsed
* successfully or nothing if there was a parsing error
* successfully or nothing if there was a parsing error
*/
public static Optional<Property> parseProperty(String value, Map<String, Vocab> vocabs,
ValidationContext context, EPUBLocation location)
Expand All @@ -64,13 +64,13 @@ public static Optional<Property> parseProperty(String value, Map<String, Vocab>
* errors on the fly.
*
* @param value
* the value to parse.
* the value to parse.
* @param vocabs
* a map of prefix to vocabularies.
* a map of prefix to vocabularies.
* @param context
* the validation context (report, locale, path, etc).
* the validation context (report, locale, path, etc).
* @param location
* the location in the validated file.
* the location in the validated file.
* @return
*/
public static Set<Property> parsePropertyList(String value, Map<String, ? extends Vocab> vocabs,
Expand Down Expand Up @@ -158,17 +158,17 @@ private static Set<Property> parseProperties(String value, Map<String, ? extends
* vocabularies, and default vocabularies that cannot be re-declared.
*
* @param value
* the prefix declaration to parse.
* the prefix declaration to parse.
* @param predefined
* a map of reserved prefixes to associated vocabularies.
* a map of reserved prefixes to associated vocabularies.
* @param known
* a map of known URIs to known vocabularies.
* a map of known URIs to known vocabularies.
* @param forbidden
* a set of URIs of default vocabularies that cannot be re-declared.
* a set of URIs of default vocabularies that cannot be re-declared.
* @param report
* to report errors on the fly.
* to report errors on the fly.
* @param location
* the location of the attribute in the source file.
* the location of the attribute in the source file.
* @return
*/
public static Map<String, Vocab> parsePrefixDeclaration(String value,
Expand All @@ -192,6 +192,10 @@ else if (forbidden.contains(uri))
// must not declare a default vocab
report.message(MessageId.OPF_007b, location, prefix);
}
else if ("http://purl.org/dc/elements/1.1/".equals(uri))
{
report.message(MessageId.OPF_007c, location);
}
else
{
if (predefined.containsKey(prefix)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ OPF_006=Invalid prefix declaration: URI "%1$s" is not a valid URI.
OPF_007=Re-declaration of reserved prefix "%1$s".
OPF_007a=Invalid prefix mapping: prefix "_" must not be declared.
OPF_007b=Invalid prefix mapping: default vocabulary "%1$s" must not be re-declared.
OPF_007c=Invalid prefix mapping: a prefix to the Dublin Core /elements/1.1/ namespace must not be declared
OPF_010=Error resolving reference: "%1$s".
OPF_011=itemref can’t have both page-spread-right and page-spread-left properties.
OPF_012=Item property "%1$s" is not defined for media type "%2$s".
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
svg.generic.attr =
attribute *
- ( id
| epub:type
| epub:*
) { text }

# Attribute list of elements where `epub:type` is allowed
Expand Down
6 changes: 6 additions & 0 deletions src/test/resources/epub3/00-minimal/files/minimal.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/test/resources/epub3/00-minimal/minimal.feature
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@
Scenario: Verify a minimal XHTML content document
When checking file 'minimal.xhtml'
Then no errors or warnings are reported

Scenario: Verify a minimal SVG content document
When checking file 'minimal.svg'
Then no errors or warnings are reported
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,6 @@ Feature: EPUB 3 — Content Documents — XHTML
When checking document 'epubtype-reserved-vocab-valid.xhtml'
Then no errors or warnings are reported

@spec @xref:sec-prefix-attr
Scenario: Verify `epub:type` attribute with author-declared vocabulary
When checking document 'epubtype-declared-vocab-valid.xhtml'
Then no errors or warnings are reported
Expand All @@ -717,13 +716,6 @@ Feature: EPUB 3 — Content Documents — XHTML
Then usage OPF-087 is reported 7 times
And no other errors or warnings are reported

@spec @xref:sec-prefix-attr
Scenario: Report `epub:type` attribute with a semantic from an undeclared vocabulary
When checking document 'epubtype-prefix-undeclared-error.xhtml'
Then error OPF-028 is reported
And no other errors or warnings are reported


#### 6.1.3.2 RDFa

@spec @xref:sec-xhtml-rdfa
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
<title>epub:type with declared vocabulary</title>
</head>
<!-- this property is part of a declared vocab -->
<!--
note: 'subchatper' is deprecated in the SSV,
but not here as it comes from another vocab
-->
<body epub:type="my:subchapter">
<h1>Test</h1>
</body>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,6 @@ Feature: EPUB 3 — Media Overlays
When checking document 'epubtype-prefix-declared-valid.smil'
Then no errors or warnings are reported

Scenario: Report an epub:type property with an undeclared prefix
When checking document 'epubtype-prefix-undeclared-error.smil'
Then error OPF-028 is reported
And the message contains 'Undeclared prefix: "my"'
And no other errors or warnings are reported

Scenario: Allow unknown epub:type properties in the default vocabulary
Given the reporting level set to usage
When checking document 'epubtype-unknown-usage.smil'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<smil xmlns="http://www.w3.org/ns/SMIL" xmlns:epub="http://www.idpf.org/2007/ops"
prefix="my: https://example.org/vocab/#" version="3.0">
<body epub:type="my:type">
<par id="par1">
<text src="chapter1.xhtml#text1"/>
<audio src="chapter1.mp3" clipBegin="0s" clipEnd="10s"/>
</par>
<par id="par2">
<text src="chapter1.xhtml#text2"/>
<audio src="chapter1.mp3" clipBegin="10s" clipEnd="20s"/>
</par>
</body>
</smil>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:epub="http://www.idpf.org/2007/ops"
prefix="my: https://example.org/vocab/#"
xml:lang="en" lang="en">
<head>
<meta charset="utf-8" />
<title>Test</title>
</head>
<body epub:type="my:type">
<h1>Loomings</h1>
<p>Call me Ishmael.</p>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en"
lang="en">
<head epub:prefix="ex1: http://example.org/vocab1
ex2: http://example.org/vocab2">
<meta charset="utf-8" />
<title>Test</title>
</head>
<body>
<h1>Loomings</h1>
<p>Call me Ishmael.</p>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en"
lang="en">
<head>
<meta charset="utf-8" />
<title>Test</title>
</head>
<body>
<h1>Loomings</h1>
<p>Call me Ishmael.</p>
<svg xmlns="http://www.w3.org/2000/svg" epub:prefix="my: http://example.org/vocab/">
<title>SVG</title>
<desc>Description</desc>
<circle r="10"/>
</svg>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<smil xmlns="http://www.w3.org/ns/SMIL" xmlns:epub="http://www.idpf.org/2007/ops"
epub:prefix="my: https://example.org/vocab/#" version="3.0">
<body>
<par id="par1">
<text src="chapter1.xhtml#text1"/>
<audio src="chapter1.mp3" clipBegin="0s" clipEnd="10s"/>
</par>
<par id="par2">
<text src="chapter1.xhtml#text2"/>
<audio src="chapter1.mp3" clipBegin="10s" clipEnd="20s"/>
</par>
</body>
</smil>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:epub="http://www.idpf.org/2007/ops"
epub:prefix="ex1: http://example.org/vocab1
ex2: http://example.org/vocab2"
xml:lang="en" lang="en">
<head>
<meta charset="utf-8" />
<title>Test</title>
</head>
<body>
<h1>Loomings</h1>
<p>Call me Ishmael.</p>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:epub="http://www.idpf.org/2007/ops"
epub:prefix="my: https://example.org/vocab/#"
xml:lang="en" lang="en">
<head>
<meta charset="utf-8" />
<title>Test</title>
</head>
<!--
note: 'subchatper' is deprecated in the SSV,
but not here as it comes from another vocab
-->
<body epub:type="my:subchapter">
<h1>Loomings</h1>
<p>Call me Ishmael.</p>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<package xmlns="http://www.idpf.org/2007/opf" version="3.0" unique-identifier="uid"
xmlns:dc="http://purl.org/dc/elements/1.1/"
prefix="dc: http://purl.org/dc/elements/1.1/">
<metadata>
<dc:title>Title</dc:title>
<dc:language>en</dc:language>
<dc:identifier id="uid">NOID</dc:identifier>
<meta property="dcterms:modified">2019-01-01T12:00:00Z</meta>
</metadata>
<manifest>
<item id="t001" href="contents.xhtml" properties="nav" media-type="application/xhtml+xml"/>
</manifest>
<spine>
<itemref idref="t001"/>
</spine>
</package>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:epub="http://www.idpf.org/2007/ops"
epub:prefix="my: https://example.org/vocab/#"
xml:lang="en" lang="en">
<head>
<meta charset="utf-8" />
<title>Valid `epub:prefix` attribute</title>
</head>
<body>
<h1>Loomings</h1>
<p>Call me Ishmael.</p>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:epub="http://www.idpf.org/2007/ops"
epub:prefix="msv: http://www.idpf.org/epub/vocab/structure/magazine/#
prism: http://www.prismstandard.org/specifications/3.0/PRISM_CV_Spec_3.0.htm#"
xml:lang="en" lang="en">
<head>
<meta charset="utf-8" />
<title>Test</title>
</head>
<body>
<h1>Loomings</h1>
<p>Call me Ishmael.</p>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en"
epub:prefix="msv: http://example.org/msv/
prism: http://example.org/prism/" lang="en">
<head>
<meta charset="utf-8" />
<title>Test</title>
</head>
<body>
<h1 epub:type="prism:title">Loomings</h1>
<p>Call me Ishmael.</p>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en"
lang="en">
<head>
<meta charset="utf-8" />
<title>Test</title>
</head>
<body>
<h1 epub:type="prism:title">Loomings</h1>
<p>Call me Ishmael.</p>
</body>
</html>
Loading
Loading