From 0175818bd68d9f1f451de4fca8490edcb56e00ef Mon Sep 17 00:00:00 2001 From: Romain Deltour Date: Thu, 15 Dec 2022 09:38:19 +0100 Subject: [PATCH] feat: disallow data URLs in the package document EPUB 3.3 now disallows data URLs everywhere in the package document (in both `item` and `link` elements). See https://github.com/w3c/epub-specs/pull/2494 Fix #1446 --- .../com/adobe/epubcheck/opf/OPFChecker30.java | 9 +++- .../com/adobe/epubcheck/opf/OPFHandler30.java | 15 ++++-- .../EPUB/content_001.xhtml | 37 -------------- .../EPUB/image.jpeg | Bin 1962 -> 0 bytes .../EPUB/nav.xhtml | 14 ------ .../EPUB/package.opf | 45 ------------------ .../META-INF/container.xml | 6 --- .../mimetype | 1 - ...pf => data-url-in-manifest-item-error.opf} | 0 .../files/data-url-in-package-link-error.opf | 17 +++++++ .../epub3/03-resources/resources.feature | 20 ++++---- 11 files changed, 45 insertions(+), 119 deletions(-) delete mode 100644 src/test/resources/epub3/03-resources/files/data-url-in-html-img-foreign-manifest-fallback-valid/EPUB/content_001.xhtml delete mode 100644 src/test/resources/epub3/03-resources/files/data-url-in-html-img-foreign-manifest-fallback-valid/EPUB/image.jpeg delete mode 100644 src/test/resources/epub3/03-resources/files/data-url-in-html-img-foreign-manifest-fallback-valid/EPUB/nav.xhtml delete mode 100644 src/test/resources/epub3/03-resources/files/data-url-in-html-img-foreign-manifest-fallback-valid/EPUB/package.opf delete mode 100644 src/test/resources/epub3/03-resources/files/data-url-in-html-img-foreign-manifest-fallback-valid/META-INF/container.xml delete mode 100644 src/test/resources/epub3/03-resources/files/data-url-in-html-img-foreign-manifest-fallback-valid/mimetype rename src/test/resources/epub3/03-resources/files/{data-url-in-manifest-item-valid.opf => data-url-in-manifest-item-error.opf} (100%) create mode 100644 src/test/resources/epub3/03-resources/files/data-url-in-package-link-error.opf diff --git a/src/main/java/com/adobe/epubcheck/opf/OPFChecker30.java b/src/main/java/com/adobe/epubcheck/opf/OPFChecker30.java index f5bcbeede..38427d3cb 100644 --- a/src/main/java/com/adobe/epubcheck/opf/OPFChecker30.java +++ b/src/main/java/com/adobe/epubcheck/opf/OPFChecker30.java @@ -85,6 +85,12 @@ protected boolean checkContent() @Override protected void checkItem(OPFItem item, OPFHandler opfHandler) { + // Items with `data:` URLs are not allowed in EPUB 3 + if (item.hasDataURL()) + { + report.message(MessageId.RSC_029, item.getLocation()); + return; + } if (item.getPath().startsWith("META-INF/")) { report.message(MessageId.PKG_025, item.getLocation()); @@ -182,10 +188,9 @@ else if (!overlayTextChecker.isCorrectOverlay(docURL, mo)) @Override protected void checkSpineItem(OPFItem item, OPFHandler opfHandler) { - // Items with `data:` URLs are not allowed in the spine + // Items with `data:` URLs are not allowed and reported earlier if (item.hasDataURL()) { - report.message(MessageId.RSC_029, item.getLocation()); return; } diff --git a/src/main/java/com/adobe/epubcheck/opf/OPFHandler30.java b/src/main/java/com/adobe/epubcheck/opf/OPFHandler30.java index 60208082b..018f753db 100644 --- a/src/main/java/com/adobe/epubcheck/opf/OPFHandler30.java +++ b/src/main/java/com/adobe/epubcheck/opf/OPFHandler30.java @@ -393,12 +393,17 @@ private void processLink() { XMLElement e = currentElement(); + // check the 'href' URL + // href presence is checked by schema String href = e.getAttribute("href"); - if (href != null) - { // href presence is checked by schema - - // check the 'href' URL - URL url = checkURL(href); + URL url = checkURL(href); + if (url != null) + { + // Data URLs are not allowed on `link` elements + if ("data".equals(url.scheme())) { + report.message(MessageId.RSC_029, location()); + return; + } if (context.isRemote(url)) { report.info(path, FeatureEnum.REFERENCE, href); diff --git a/src/test/resources/epub3/03-resources/files/data-url-in-html-img-foreign-manifest-fallback-valid/EPUB/content_001.xhtml b/src/test/resources/epub3/03-resources/files/data-url-in-html-img-foreign-manifest-fallback-valid/EPUB/content_001.xhtml deleted file mode 100644 index 6d1175045..000000000 --- a/src/test/resources/epub3/03-resources/files/data-url-in-html-img-foreign-manifest-fallback-valid/EPUB/content_001.xhtml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - Minimal EPUB - - - the whale - - diff --git a/src/test/resources/epub3/03-resources/files/data-url-in-html-img-foreign-manifest-fallback-valid/EPUB/image.jpeg b/src/test/resources/epub3/03-resources/files/data-url-in-html-img-foreign-manifest-fallback-valid/EPUB/image.jpeg deleted file mode 100644 index ff336a51f6dead6a18ee333037587f44c8f1c62f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1962 zcmZ9NX;jh)7smgrBBim55Q!@iBBDT6Clzx+6Bk^{$QCsbt$AGrM$%~^v@Em2HOF#I zkrdNRGt1Ocb1coYM$M_5#$MOAGOgyc_|lnk=EL0k&d zAOHaA8(4V;r~pGa9E(BYa3~xBkHce$M4|}}PcbninVFgpC?;m>$d(k^dJ4tTY%Rge z(azF|%d)dGH)C@h);rrU?CBswB+_V=5owJviD_YG#bq&h4i0u)t{s=fVRG%*4m=i* z!?Rs>mF%j9sr&#aXW0F3}P0$C7{1pr2aAZXCaJ%9`VUa4?_+NA|1PTMe^_~qH0E0mgFdXvFWj!4Y#jvsFFbh4r!O`j1$~dqZ z0@BBYpaEAPr4xz*;R}>+xi)>W*-5f`eMO;ZN;l2Z5Zor&P-xFz^Fw4q^yjuQ6Y0R0_{miCI`)s)3+3(>g6w7X*V>NZm(`?Jf7(h zuZm6a_)rJWk3E5^=&;2uq%XHju@0Mm@-h+*+-&Js>|4kVyq9;u*qkAZEk)>Bdw0|~ z5TMt%)U+bm6n0xFQcdq^P3bwgjV;Wl<)$hvErz3u3{U|;!{=Vv4WNc?73aSd?|q4}s~hoh-|=Yi0U>W~exg0~jnDAaGyHk>(NTXTf{KhEO5H#I z;bwRqI@sf~g*IrAx;a~78!CK34jT`T8<6_3%X5v_wtsHBjgt&)NcFstG31`0O^29| zGla5{KcxeNu%BDvcAV-cd)#07I{mmRX;br&mSRxrO)(+Apdv@|sX$hSi(Pl`uZbs< zSl-Qqu}{J3I2hbrnTwmO^t&kz%qb}s=`vp}`=2vh3N3HDHh(g8-=f*;ujS)Mq7Mf} z+)=fgW{rL=&Bya5@f89g?+^kz^oxtV({sZr0bd8^}rxS?@Fx4^9A+Le2Bbuz;k6q5CK6Y6wdndn@EnZwW zTog6CY$6OYxul?1X=Kq2onnPOuIUfKP9W$xJoJ^Yw@HL2=mx9jdk;ws2=ovB6~{K& z%578bK9(z*19vH;2MtYY;tV0Tx|-iFXqXYO{Gp$_W$q(N{u22~#1bWABTev8#v8?z zKCBv({;FEa^y%`y7#(+MHaqaCs(XA4`k=o&=1D?@gYJw~6o(6(f8sVDpk4bGgqFDGpasKR^GXlQ`8u5gbOPe_|IF?$H>K5vF4z4wLg02WpBS_gA+vUEyvE5w~)Y$ zXTpHJnV1a`0geUa9Z)qgw94xO8mAe(&XUksm7a9Q<|Jv|>4Qz2T83|~$lZ-vRHBNi zHO0J|7Cb^#^tn!>_jW%>yVT(Bjq<%6g4Q<9=Q1^e?rL(s*X%Y37`Cr=hR26nV`)utL%uobOB7^$qHB}aA$!C^JY)I1PPAlGcpy9}* z05V3ItIL{IZMR+2PLZu?ck%M}K}lWslUB}5T&UGv11C3F!iMtX=e2*`1(s`Ke8?$F$qkT$p3 tR2BM$*=lqAV;Ul(=0!E9u8+;$x3y;KABX3?E(G-`f~o|lN(5wO?Em1hBGLc= diff --git a/src/test/resources/epub3/03-resources/files/data-url-in-html-img-foreign-manifest-fallback-valid/EPUB/nav.xhtml b/src/test/resources/epub3/03-resources/files/data-url-in-html-img-foreign-manifest-fallback-valid/EPUB/nav.xhtml deleted file mode 100644 index 240745e63..000000000 --- a/src/test/resources/epub3/03-resources/files/data-url-in-html-img-foreign-manifest-fallback-valid/EPUB/nav.xhtml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - Minimal Nav - - - - - diff --git a/src/test/resources/epub3/03-resources/files/data-url-in-html-img-foreign-manifest-fallback-valid/EPUB/package.opf b/src/test/resources/epub3/03-resources/files/data-url-in-html-img-foreign-manifest-fallback-valid/EPUB/package.opf deleted file mode 100644 index 2a1ff0420..000000000 --- a/src/test/resources/epub3/03-resources/files/data-url-in-html-img-foreign-manifest-fallback-valid/EPUB/package.opf +++ /dev/null @@ -1,45 +0,0 @@ - - - - Minimal EPUB 3.0 - en - NOID - 2017-06-14T00:00:01Z - - - - - - - - - - - diff --git a/src/test/resources/epub3/03-resources/files/data-url-in-html-img-foreign-manifest-fallback-valid/META-INF/container.xml b/src/test/resources/epub3/03-resources/files/data-url-in-html-img-foreign-manifest-fallback-valid/META-INF/container.xml deleted file mode 100644 index 318782179..000000000 --- a/src/test/resources/epub3/03-resources/files/data-url-in-html-img-foreign-manifest-fallback-valid/META-INF/container.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/src/test/resources/epub3/03-resources/files/data-url-in-html-img-foreign-manifest-fallback-valid/mimetype b/src/test/resources/epub3/03-resources/files/data-url-in-html-img-foreign-manifest-fallback-valid/mimetype deleted file mode 100644 index 57ef03f24..000000000 --- a/src/test/resources/epub3/03-resources/files/data-url-in-html-img-foreign-manifest-fallback-valid/mimetype +++ /dev/null @@ -1 +0,0 @@ -application/epub+zip \ No newline at end of file diff --git a/src/test/resources/epub3/03-resources/files/data-url-in-manifest-item-valid.opf b/src/test/resources/epub3/03-resources/files/data-url-in-manifest-item-error.opf similarity index 100% rename from src/test/resources/epub3/03-resources/files/data-url-in-manifest-item-valid.opf rename to src/test/resources/epub3/03-resources/files/data-url-in-manifest-item-error.opf diff --git a/src/test/resources/epub3/03-resources/files/data-url-in-package-link-error.opf b/src/test/resources/epub3/03-resources/files/data-url-in-package-link-error.opf new file mode 100644 index 000000000..298833381 --- /dev/null +++ b/src/test/resources/epub3/03-resources/files/data-url-in-package-link-error.opf @@ -0,0 +1,17 @@ + + + + Minimal EPUB 3.0 + en + NOID + 2017-06-14T00:00:01Z + + + + + + + + + + diff --git a/src/test/resources/epub3/03-resources/resources.feature b/src/test/resources/epub3/03-resources/resources.feature index c9e49aa70..51a20fb00 100644 --- a/src/test/resources/epub3/03-resources/resources.feature +++ b/src/test/resources/epub3/03-resources/resources.feature @@ -493,16 +493,23 @@ ## 3.7 Data URLs @spec @xref:sec-data-urls - Scenario: Allow a data URL in a manifest item not in the spine - When checking file 'data-url-in-manifest-item-valid.opf' - Then no errors or warnings are reported + Scenario: Report a data URL in a manifest item href (not in the spine) + When checking file 'data-url-in-manifest-item-error.opf' + Then error RSC-029 is reported + And no other errors or warnings are reported @spec @xref:sec-data-urls - Scenario: Report a data URL in a manifest item referenced in the spine + Scenario: Report a data URL in a manifest item href (referenced in the spine) When checking file 'data-url-in-manifest-item-in-spine-error.opf' Then error RSC-029 is reported And no other errors or warnings are reported + @spec @xref:sec-data-urls + Scenario: Report a data URL in a package link href + When checking file 'data-url-in-package-link-error.opf' + Then error RSC-029 is reported + And no other errors or warnings are reported + @spec @xref:sec-data-urls Scenario: Report a data URL in the `href` attribute of an HTML `a` element When checking file 'data-url-in-html-a-href-error.xhtml' @@ -536,11 +543,6 @@ When checking EPUB 'data-url-in-html-img-foreign-intrinsic-fallback-valid' And no errors or warnings are reported - @spec @xref:sec-data-urls - Scenario: Allow a data URL defining a foreign resource with a manifest fallback (in an HTML `img` element) - When checking EPUB 'data-url-in-html-img-foreign-manifest-fallback-valid' - And no errors or warnings are reported - @spec @xref:sec-data-urls Scenario: Report a data URL defining a foreign resource with no fallback (in an HTML `img` element) When checking EPUB 'data-url-in-html-img-foreign-no-fallback-error'