Skip to content

Commit

Permalink
feat: report 'file' URLs as errors
Browse files Browse the repository at this point in the history
Report `file:` URLs as a new error RSC-030

Fixes #1270
  • Loading branch information
rdeltour committed Nov 27, 2022
1 parent a3c736d commit 0f6b509
Show file tree
Hide file tree
Showing 15 changed files with 70 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private void initialize()
severities.put(MessageId.HTM_050, Severity.SUPPRESSED);
severities.put(MessageId.HTM_051, Severity.WARNING);
severities.put(MessageId.HTM_052, Severity.ERROR);
severities.put(MessageId.HTM_053, Severity.INFO);
severities.put(MessageId.HTM_053, Severity.SUPPRESSED);
severities.put(MessageId.HTM_054, Severity.ERROR);
severities.put(MessageId.HTM_055, Severity.WARNING);
severities.put(MessageId.HTM_056, Severity.ERROR);
Expand Down Expand Up @@ -343,6 +343,7 @@ private void initialize()
severities.put(MessageId.RSC_027, Severity.WARNING);
severities.put(MessageId.RSC_028, Severity.ERROR);
severities.put(MessageId.RSC_029, Severity.ERROR);
severities.put(MessageId.RSC_030, Severity.ERROR);

// Scripting
severities.put(MessageId.SCP_001, Severity.SUPPRESSED); // checking scripts is out of scope
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 @@ -337,6 +337,7 @@ public enum MessageId implements Comparable<MessageId>
RSC_027("RSC-027"),
RSC_028("RSC-028"),
RSC_029("RSC-029"),
RSC_030("RSC-030"),

// Messages relating to scripting
SCP_001("SCP-001"),
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/com/adobe/epubcheck/ops/OPSHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,6 @@ else if (".".equals(href))
// If the URL was not properly parsed, return early
if (url == null) return;

if ("file".equals(url.scheme()))
{
// FIXME next disallow file URLs
report.message(MessageId.HTM_053, location(), url);
}
if (context.isRemote(url))
{
report.info(path, FeatureEnum.REFERENCE, href);
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/w3c/epubcheck/url/URLChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ private URL resolveURL(String string, boolean isBase, EPUBLocation location)
if (string == null) return null;
try
{
// Report file URLs
if (string.startsWith("file:"))
{
report.message(MessageId.RSC_030, location, string);
}

// Collapse formatting whitespace in data URLs
if (string.startsWith("data:"))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ HTM_049_SUG=Add xmlns="http://www.w3.org/1999/xhtml" to the html element.
HTM_050=Found epub:type="pagebreak" attribute in content document.
HTM_051=Found Microdata semantic enrichments but no RDFa. EDUPUB recommends using RDFa Lite.
HTM_052=The property "region-based" is only allowed on nav elements in Data Navigation Documents.
HTM_053=Found an external file link (file://) in file: "%1$s".
HTM_054=Custom attribute namespace ("%1$s") must not include the string "%2$s" in its domain.
HTM_055=The "%1$s" element should not be used (discouraged construct)
HTM_056=Viewport metadata has no "%1$s" dimension (both "width" and "height" properties are required)
Expand Down Expand Up @@ -353,6 +352,7 @@ RSC_026=URL "%1$s" leaks outside the container (it is not a valid-relative-ocf-U
RSC_027=XML document is encoded in UTF-16. It should be encoded in UTF-8 instead.
RSC_028=XML documents must be encoded in UTF-8, but %1%s was detected.
RSC_029=Data URL is not allowed in this context.
RSC_030=File URLs are not allowed in EPUB, but found "%1$s".

#Scripting
SCP_001=Use of Javascript eval() function in EPUB scripts is a security risk.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
<head>
<meta charset="utf-8"/>
<title>Minimal EPUB</title>
<link type="text/css" rel="stylesheet" href="style.css" />
</head>
<body>
<h1>Loomings</h1>
<p>Call me Ishmael.</p>
<a class="external" href="file:///C:/path/file.pdf">link to local file</a>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<package xmlns="http://www.idpf.org/2007/opf" version="3.0" xml:lang="en" unique-identifier="q">
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/">
<dc:title id="title">Minimal EPUB 3.0</dc:title>
<dc:language>en</dc:language>
<dc:identifier id="q">NOID</dc:identifier>
<meta property="dcterms:modified">2017-06-14T00:00:01Z</meta>
</metadata>
<manifest>
<item id="content_001" href="content_001.xhtml" media-type="application/xhtml+xml"/>
<item id="nav" href="nav.xhtml" media-type="application/xhtml+xml" properties="nav"/>
<item id="css" href="style.css" media-type="text/css" properties="remote-resources"/>
<item id="font" href="file:///font.woff" media-type="font/woff"/>
</manifest>
<spine>
<itemref idref="content_001"/>
</spine>
</package>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@font-face {
font-family: "myfont";
src: url('file:/font.woff');
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
<?xml version="1.0" encoding="UTF-8"?>
<container xmlns="urn:oasis:names:tc:opendocument:xmlns:container" version="1.0">
<rootfiles>
<rootfile full-path="EPUB/package.opf" media-type="application/oebps-package+xml"/>
</rootfiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<dc:language>en</dc:language>
<dc:identifier id="q">NOID</dc:identifier>
<meta property="dcterms:modified">2017-06-14T00:00:01Z</meta>
<link href="file:example" rel="acquire"/>
</metadata>
<manifest>
<item id="content_001" href="content_001.xhtml" media-type="application/xhtml+xml"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta charset="utf-8"/>
<title>Minimal EPUB</title>
</head>
<body>
<h1>Loomings</h1>
<p>Call me Ishmael.</p>
<a href="file:example">file</a>
</body>
</html>
21 changes: 21 additions & 0 deletions src/test/resources/epub3/03-resources/resources.feature
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,27 @@
Then error MED-003 is reported
And no other errors or warnings are reported

## 3.8 File URLs

@spec @xref:sec-file-urls
Scenario: Report a file URL used in the package document
When checking document 'file-url-in-package-document-error.opf'
Then error RSC-030 is reported
And no other errors or warnings are reported

@spec @xref:sec-file-urls
Scenario: Report a file URL used in a content document
When checking document 'file-url-in-xhtml-content-error.xhtml'
Then error RSC-030 is reported
And no other errors or warnings are reported

@spec @xref:sec-file-urls
Scenario: Report a file URL used in a CSS document
When checking EPUB 'file-url-in-css-error'
Then error RSC-030 is reported 2 times (one in the package doc, one in the CSS)
And no other errors or warnings are reported


## 3.9 XML conformance

@spec @xref:sec-xml-constraints
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,18 +249,10 @@ Feature: EPUB 3 — Content Documents — XHTML

#### hyperlinks

@spec @xref:sec-file-urls
Scenario: Report as an INFO a hyperlink to a resource in the local file system
See issue #289
When checking EPUB 'content-xhtml-link-to-local-file-valid'
Then info HTM-053 is reported
And no errors or warnings are reported

Scenario: Do not report escaped hyperlinks to resources in the local file system
See issue #1182
When checking EPUB 'content-xhtml-link-to-local-file-escaped-valid'
Then info HTM-053 is reported 0 times
And no errors or warnings are reported
Then no errors or warnings are reported

@spec @xref:sec-container-iri
Scenario: Report a hyperlink to a resource missing from the publication
Expand Down

0 comments on commit 0f6b509

Please sign in to comment.