Skip to content

Commit 6fa3312

Browse files
committed
fix: do not report fragment-only CSS URLs
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
1 parent 5949b6c commit 6fa3312

File tree

8 files changed

+77
-4
lines changed

8 files changed

+77
-4
lines changed

src/main/java/com/adobe/epubcheck/css/CSSHandler.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,15 @@ private void resolveAndRegister(String uri, int line, int col, String context, T
320320
{
321321
if (uri != null && uri.trim().length() > 0)
322322
{
323-
String resolved = PathUtil.resolveRelativeReference(path, uri);
324-
xrefChecker.registerReference(path, correctedLineNumber(line), correctedColumnNumber(line, col), resolved, type);
325-
if (PathUtil.isRemote(resolved)) {
326-
detectedProperties.add(ITEM_PROPERTIES.REMOTE_RESOURCES);
323+
// Fragment-only URLs should be resolved relative to the host document
324+
// Since we don't have access to the path of the host document(s) here,
325+
// we ignore this case
326+
if (!uri.startsWith("#")) {
327+
String resolved = PathUtil.resolveRelativeReference(path, uri);
328+
xrefChecker.registerReference(path, correctedLineNumber(line), correctedColumnNumber(line, col), resolved, type);
329+
if (PathUtil.isRemote(resolved)) {
330+
detectedProperties.add(ITEM_PROPERTIES.REMOTE_RESOURCES);
331+
}
327332
}
328333
}
329334
else

src/test/resources/epub3/content-publication.feature

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,10 @@ Feature: EPUB 3 ▸ Content Documents ▸ Full Publication Checks
407407
When checking EPUB 'content-css-font-size-zero-valid'
408408
Then no errors or warnings are reported
409409

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

411415
## 6. Fixed Layouts
412416

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!DOCTYPE html>
2+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3+
<head>
4+
<meta charset="utf-8"/>
5+
<title>Minimal EPUB</title>
6+
<link type="text/css" rel="stylesheet" href="style.css" />
7+
</head>
8+
<body>
9+
<h1>Loomings</h1>
10+
<p>Call me Ishmael.</p>
11+
<svg version="1.1" xmlns="http://www.w3.org/2000/svg">
12+
<defs>
13+
<filter id="filter">
14+
<feColorMatrix type="matrix" values="0.3333 0.3333 0.3333 0 0
15+
0.3333 0.3333 0.3333 0 0
16+
0.3333 0.3333 0.3333 0 0
17+
0 0 0 1 0" />
18+
</filter>
19+
</defs>
20+
</svg>
21+
</body>
22+
</html>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en" lang="en">
3+
<head>
4+
<meta charset="utf-8"/>
5+
<title>Minimal Nav</title>
6+
</head>
7+
<body>
8+
<nav epub:type="toc">
9+
<ol>
10+
<li><a href="content_001.xhtml">content 001</a></li>
11+
</ol>
12+
</nav>
13+
</body>
14+
</html>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<package xmlns="http://www.idpf.org/2007/opf" version="3.0" xml:lang="en" unique-identifier="q">
3+
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/">
4+
<dc:title id="title">Minimal EPUB 3.0</dc:title>
5+
<dc:language>en</dc:language>
6+
<dc:identifier id="q">NOID</dc:identifier>
7+
<meta property="dcterms:modified">2017-06-14T00:00:01Z</meta>
8+
</metadata>
9+
<manifest>
10+
<item id="content_001" href="content_001.xhtml" media-type="application/xhtml+xml" properties="svg"/>
11+
<item id="nav" href="nav.xhtml" media-type="application/xhtml+xml" properties="nav"/>
12+
<item id="css" href="style.css" media-type="text/css" />
13+
</manifest>
14+
<spine>
15+
<itemref idref="content_001" />
16+
</spine>
17+
</package>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
body {
2+
color: inherit;
3+
filter: url(#filter);
4+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
3+
<rootfiles>
4+
<rootfile full-path="EPUB/package.opf" media-type="application/oebps-package+xml"/>
5+
</rootfiles>
6+
</container>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
application/epub+zip

0 commit comments

Comments
 (0)