GeezerVison is showing github.com — feat: improve checking of data URLs · w3c/epubcheck@cbc0b2a
File treeExpand file treeCollapse file tree Open diff view settings resources/com/adobe/epubcheck/messages
data-url-in-html-img-cmt-valid data-url-in-html-img-foreign-intrinsic-fallback-valid data-url-in-html-img-foreign-manifest-fallback-valid data-url-in-html-img-foreign-no-fallback-error data-url-in-html-link-exempt-valid
Some content is hiddenLarge Commits have some content hidden by default. Use the searchbox below for content that may be hidden. Dismiss bannerExpand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: src/main/java/com/adobe/epubcheck/messages/DefaultSeverities.java +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -340,6 +340,7 @@ private void initialize() | 340 | 340 | severities.put(MessageId.RSC_026, Severity.ERROR); | 341 | 341 | severities.put(MessageId.RSC_027, Severity.WARNING); | 342 | 342 | severities.put(MessageId.RSC_028, Severity.ERROR); | | 343 | + severities.put(MessageId.RSC_029, Severity.ERROR); | 343 | 344 |
| 344 | 345 | // Scripting | 345 | 346 | severities.put(MessageId.SCP_001, Severity.SUPPRESSED); // checking scripts is out of scope | |
Collapse file Copy file name to clipboardExpand all lines: src/main/java/com/adobe/epubcheck/messages/MessageId.java +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -334,6 +334,7 @@ public enum MessageId implements Comparable<MessageId> | 334 | 334 | RSC_026("RSC-026"), | 335 | 335 | RSC_027("RSC-027"), | 336 | 336 | RSC_028("RSC-028"), | | 337 | + RSC_029("RSC-029"), | 337 | 338 |
| 338 | 339 | // Messages relating to scripting | 339 | 340 | SCP_001("SCP-001"), | |
Collapse file Copy file name to clipboardExpand all lines: src/main/java/com/adobe/epubcheck/ocf/OCFContainer.java +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -130,8 +130,9 @@ public boolean isRemote(URL url) | 130 | 130 | } | 131 | 131 | else | 132 | 132 | { | 133 | | - return !(URLUtils.isSameOrigin(url, rootURL)); | | 133 | + return URLUtils.isRemote(url, rootURL); | 134 | 134 | } | 135 | 135 | } | 136 | 136 |
| | 137 | + | 137 | 138 | } |
Collapse file Copy file name to clipboardExpand all lines: src/main/java/com/adobe/epubcheck/opf/OPFChecker.java +5-1Lines changed: 5 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -210,7 +210,7 @@ protected boolean checkContent() | 210 | 210 | // only check the filename in single-file mode | 211 | 211 | // (it is checked by the container checker in full-publication mode) | 212 | 212 | // and for local resources (i.e. computed to a file URL) | 213 | | - if (!context.container.isPresent() && !item.isRemote()) | | 213 | + if (!context.container.isPresent() && !item.isRemote() && !item.hasDataURL()) | 214 | 214 | { | 215 | 215 | new OCFFilenameChecker(item.getPath(), context, item.getLocation()).check(); | 216 | 216 | } | @@ -378,6 +378,10 @@ else if (isBlessedStyleType(mimeType)) | 378 | 378 |
| 379 | 379 | protected void checkItemContent(OPFItem item) | 380 | 380 | { | | 381 | + // We do not currently support checking resources defined as data URLs | | 382 | + if (item.hasDataURL()) { | | 383 | + return; | | 384 | + } | 381 | 385 | // Create a new validation context for the OPF item | 382 | 386 | // FIXME 2022 set context OPFItem here | 383 | 387 | // (instead of from XRefChecker in the builder code) | |
Collapse file Copy file name to clipboardExpand all lines: src/main/java/com/adobe/epubcheck/opf/OPFChecker30.java +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -186,6 +186,12 @@ else if (!overlayTextChecker.isCorrectOverlay(docURL, mo)) | 186 | 186 | @Override | 187 | 187 | protected void checkSpineItem(OPFItem item, OPFHandler opfHandler) | 188 | 188 | { | | 189 | + // Items with `data:` URLs are not allowed in the spine | | 190 | + if (item.hasDataURL()) { | | 191 | + report.message(MessageId.RSC_029, item.getLocation()); | | 192 | + return; | | 193 | + } | | 194 | + | 189 | 195 | String mimeType = item.getMimeType(); | 190 | 196 |
| 191 | 197 | if (item.getProperties() | |
Collapse file Copy file name to clipboardExpand all lines: src/main/java/com/adobe/epubcheck/opf/OPFItem.java +17Lines changed: 17 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -109,6 +109,13 @@ private OPFItem(Builder builder) | 109 | 109 | { | 110 | 110 | this.path = url.toHumanString(); | 111 | 111 | } | | 112 | + // If the item is defined with a data URL, return | | 113 | + // the URL string truncated arbitrarily to 30 chars | | 114 | + else if ("data".equals(url.scheme())) | | 115 | + { | | 116 | + String urlString = url.toString(); | | 117 | + this.path = url.toString().substring(0, Math.min(urlString.length(), 30)) + "…"; | | 118 | + } | 112 | 119 | // If a container is present (full-publication check) | 113 | 120 | // the item path is relative to the root of the container | 114 | 121 | else if (builder.container.isPresent()) | @@ -289,6 +296,16 @@ public boolean isFixedLayout() | 289 | 296 | return fixedLayout; | 290 | 297 | } | 291 | 298 |
| | 299 | + /** | | 300 | + * Returns <code>true</code> iff this item is a remote resource. | | 301 | + * | | 302 | + * @return <code>true</code> iff this item is a remote resource. | | 303 | + */ | | 304 | + public boolean hasDataURL() | | 305 | + { | | 306 | + return "data".equals(url.scheme()); | | 307 | + } | | 308 | + | 292 | 309 | /** | 293 | 310 | * Returns <code>true</code> iff this item is a remote resource. | 294 | 311 | * | |
Collapse file Copy file name to clipboardExpand all lines: src/main/java/com/adobe/epubcheck/opf/ValidationContext.java +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -141,7 +141,7 @@ private String computePath() | 141 | 141 | { | 142 | 142 | if (container.isPresent() && !container.get().isRemote(url)) | 143 | 143 | { | 144 | | - if (!url.path().isEmpty()) | | 144 | + if (url.path() != null && !url.path().isEmpty()) | 145 | 145 | { | 146 | 146 | return url.path().substring(1); | 147 | 147 | } | @@ -181,7 +181,7 @@ public boolean isRemote(URL url) | 181 | 181 | } | 182 | 182 | else | 183 | 183 | { | 184 | | - return !(URLUtils.isSameOrigin(url, this.url)); | | 184 | + return URLUtils.isRemote(url, this.url); | 185 | 185 | } | 186 | 186 | } | 187 | 187 |
| |
|