Skip to content

Commit

Permalink
fix: do not report fragment-only CSS URLs
Browse files Browse the repository at this point in the history
CSS defines a special processing for the resolution of fragment-only URLs.
These are resolved based on the HTML document, not relative to the
stylesheet.

For example, an SVG filter inlined in the HTML can be refered in CSS as:

```
* {
  filter: url(#filter);
}
```

Such fragment-only URLs were previously reported as errors in EPUBCheck,
since the related fragment could not be found in the CSS document!

This change fixes the issue by ignoring fragment-only URLs in CSS. In
other words, these URLs will not be registered to the XRefChecker.

Fixes #1198
  • Loading branch information
rdeltour committed Feb 26, 2021
1 parent 5949b6c commit 6fa3312
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/main/java/com/adobe/epubcheck/css/CSSHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,15 @@ private void resolveAndRegister(String uri, int line, int col, String context, T
{
if (uri != null && uri.trim().length() > 0)
{
String resolved = PathUtil.resolveRelativeReference(path, uri);
xrefChecker.registerReference(path, correctedLineNumber(line), correctedColumnNumber(line, col), resolved, type);
if (PathUtil.isRemote(resolved)) {
detectedProperties.add(ITEM_PROPERTIES.REMOTE_RESOURCES);
// Fragment-only URLs should be resolved relative to the host document
// Since we don't have access to the path of the host document(s) here,
// we ignore this case
if (!uri.startsWith("#")) {
String resolved = PathUtil.resolveRelativeReference(path, uri);
xrefChecker.registerReference(path, correctedLineNumber(line), correctedColumnNumber(line, col), resolved, type);
if (PathUtil.isRemote(resolved)) {
detectedProperties.add(ITEM_PROPERTIES.REMOTE_RESOURCES);
}
}
}
else
Expand Down
4 changes: 4 additions & 0 deletions src/test/resources/epub3/content-publication.feature
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,10 @@ Feature: EPUB 3 ▸ Content Documents ▸ Full Publication Checks
When checking EPUB 'content-css-font-size-zero-valid'
Then no errors or warnings are reported

Scenario: Verify a fragment-only URL does not trigger a "fragment not defined" error
When checking EPUB 'content-css-url-fragment-valid'
Then no errors or warnings are reported


## 6. Fixed Layouts

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<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>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg">
<defs>
<filter id="filter">
<feColorMatrix type="matrix" values="0.3333 0.3333 0.3333 0 0
0.3333 0.3333 0.3333 0 0
0.3333 0.3333 0.3333 0 0
0 0 0 1 0" />
</filter>
</defs>
</svg>
</body>
</html>
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" xml:lang="en" lang="en">
<head>
<meta charset="utf-8"/>
<title>Minimal Nav</title>
</head>
<body>
<nav epub:type="toc">
<ol>
<li><a href="content_001.xhtml">content 001</a></li>
</ol>
</nav>
</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" 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" properties="svg"/>
<item id="nav" href="nav.xhtml" media-type="application/xhtml+xml" properties="nav"/>
<item id="css" href="style.css" media-type="text/css" />
</manifest>
<spine>
<itemref idref="content_001" />
</spine>
</package>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
body {
color: inherit;
filter: url(#filter);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
<rootfiles>
<rootfile full-path="EPUB/package.opf" media-type="application/oebps-package+xml"/>
</rootfiles>
</container>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
application/epub+zip

0 comments on commit 6fa3312

Please sign in to comment.