[jira] [Commented] (BATIK-1227) Image filters encoded with Base64 in the SVG throw "Content not allowed in prolog" exception

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (BATIK-1227) Image filters encoded with Base64 in the SVG throw "Content not allowed in prolog" exception

Simon Steiner (Jira)

    [ https://issues.apache.org/jira/browse/BATIK-1227?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17151986#comment-17151986 ]

Simon Steiner commented on BATIK-1227:
--------------------------------------

Can you add a unit test

> Image filters encoded with Base64 in the SVG throw "Content not allowed in prolog" exception
> --------------------------------------------------------------------------------------------
>
>                 Key: BATIK-1227
>                 URL: https://issues.apache.org/jira/browse/BATIK-1227
>             Project: Batik
>          Issue Type: Bug
>          Components: Bridge
>    Affects Versions: 1.9
>            Reporter: Dan Caprioara
>            Priority: Major
>
> Having this SVG:
> {code:xml}
> <svg id="note" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="20" height="20" viewBox="0 0 20 20">
>   <defs>
>     <style>
>       .cls-1 {
>         fill: #e99915;
>         filter: url(#filter);
>       }
>       .cls-1, .cls-2, .cls-3, .cls-4, .cls-5 {
>         fill-rule: evenodd;
>       }
>       .cls-2 {
>         fill: #cbcbcb;
>         filter: url(#filter-2);
>       }
>       .cls-3 {
>         fill: red;
>         filter: url(#filter-3);
>       }
>       .cls-4 {
>         fill: #b04a1a;
>       }
>       .cls-5 {
>         fill: #cd803c;
>       }
>     </style>
>     <filter id="filter" x="2" y="2" width="16" height="16" filterUnits="userSpaceOnUse">
>       <feImage preserveAspectRatio="none" x="2" y="2" width="16" height="16" result="image" xlink:href="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHZpZXdCb3g9IjAgMCAxNiAxNiI+CiAgPGRlZnM+CiAgICA8c3R5bGU+CiAgICAgIC5jbHMtMSB7CiAgICAgICAgZmlsbDogdXJsKCNsaW5lYXItZ3JhZGllbnQpOwogICAgICB9CiAgICA8L3N0eWxlPgogICAgPGxpbmVhckdyYWRpZW50IGlkPSJsaW5lYXItZ3JhZGllbnQiIHgxPSI4IiB5MT0iMTYiIHgyPSI4IiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSI+CiAgICAgIDxzdG9wIG9mZnNldD0iMCIgc3RvcC1jb2xvcj0iI2JkNzUzNSIvPgogICAgICA8c3RvcCBvZmZzZXQ9IjEiIHN0b3AtY29sb3I9IiNkNjg2M2YiLz4KICAgIDwvbGluZWFyR3JhZGllbnQ+CiAgPC9kZWZzPgogIDxyZWN0IGNsYXNzPSJjbHMtMSIgd2lkdGg9IjE2IiBoZWlnaHQ9IjE2Ii8+Cjwvc3ZnPgo="/>
>       <feComposite result="composite" operator="in" in2="SourceGraphic"/>
>       <feBlend result="blend" in2="SourceGraphic"/>
>     </filter>
>     <filter id="filter-2" x="3" y="3" width="14" height="14" filterUnits="userSpaceOnUse">
>       <feImage preserveAspectRatio="none" x="3" y="3" width="14" height="14" result="image" xlink:href="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB3aWR0aD0iMTQiIGhlaWdodD0iMTQiIHZpZXdCb3g9IjAgMCAxNCAxNCI+CiAgPGRlZnM+CiAgICA8c3R5bGU+CiAgICAgIC5jbHMtMSB7CiAgICAgICAgZmlsbDogdXJsKCNsaW5lYXItZ3JhZGllbnQpOwogICAgICB9CiAgICA8L3N0eWxlPgogICAgPGxpbmVhckdyYWRpZW50IGlkPSJsaW5lYXItZ3JhZGllbnQiIHgxPSI3IiB5MT0iMTQiIHgyPSI3IiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSI+CiAgICAgIDxzdG9wIG9mZnNldD0iMCIgc3RvcC1jb2xvcj0iI2ZmYjk1NyIvPgogICAgICA8c3RvcCBvZmZzZXQ9IjEiIHN0b3AtY29sb3I9IiNmZmVmNWYiLz4KICAgIDwvbGluZWFyR3JhZGllbnQ+CiAgPC9kZWZzPgogIDxyZWN0IGNsYXNzPSJjbHMtMSIgd2lkdGg9IjE0IiBoZWlnaHQ9IjE0Ii8+Cjwvc3ZnPgo="/>
>       <feComposite result="composite" operator="in" in2="SourceGraphic"/>
>       <feBlend result="blend" in2="SourceGraphic"/>
>     </filter>
>     <filter id="filter-3" x="12" y="12" width="6" height="6" filterUnits="userSpaceOnUse">
>       <feImage preserveAspectRatio="none" x="12" y="12" width="6" height="6" result="image" xlink:href="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB3aWR0aD0iNiIgaGVpZ2h0PSI2IiB2aWV3Qm94PSIwIDAgNiA2Ij4KICA8ZGVmcz4KICAgIDxzdHlsZT4KICAgICAgLmNscy0xIHsKICAgICAgICBmaWxsOiB1cmwoI2xpbmVhci1ncmFkaWVudCk7CiAgICAgIH0KICAgIDwvc3R5bGU+CiAgICA8bGluZWFyR3JhZGllbnQgaWQ9ImxpbmVhci1ncmFkaWVudCIgeTE9IjAuMzkyIiB4Mj0iNiIgeTI9IjUuNjA4IiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSI+CiAgICAgIDxzdG9wIG9mZnNldD0iMCIgc3RvcC1jb2xvcj0iI2I2NzMwNCIvPgogICAgICA8c3RvcCBvZmZzZXQ9IjEiIHN0b3AtY29sb3I9IiNmOGJlNGMiLz4KICAgIDwvbGluZWFyR3JhZGllbnQ+CiAgPC9kZWZzPgogIDxyZWN0IGNsYXNzPSJjbHMtMSIgd2lkdGg9IjYiIGhlaWdodD0iNiIvPgo8L3N2Zz4K"/>
>       <feComposite result="composite" operator="in" in2="SourceGraphic"/>
>       <feBlend result="blend" in2="SourceGraphic"/>
>     </filter>
>   </defs>
>   <path id="Outer" class="cls-1" d="M2,2H18V12.719L12.563,18H2V2Z"/>
>   <path id="Fill" class="cls-2" d="M3,3H17v9.719L12.563,17H3V3Z"/>
>   <path id="FillCorner" class="cls-3" d="M13.031,13v3L12,18l6-6-2,1H13.031Z"/>
>   <path id="Lines" class="cls-4" d="M6,7V6h8V7H6Zm0,3V9h8v1H6Zm0,3V12h4v1H6Z"/>
>   <path id="Corner" class="cls-5" d="M18,12v0.707L17.707,13,13,17.707,12.707,18H12V12h6Zm-5,1v3.293L16.293,13H13Z"/>
> </svg>
> {code}
> You get:
> {quote}
> ERROR org.apache.fop.apps.FOUserAgent - SVG graphic could not be built. Reason: org.apache.batik.bridge.BridgeException: Content is not allowed in prolog.
>      [exec] org.apache.batik.bridge.BridgeException: Content is not allowed in prolog.
>      [exec] at org.apache.batik.bridge.BridgeContext.getReferencedNode(BridgeContext.java:788)
>      [exec] at org.apache.batik.bridge.BridgeContext.getReferencedElement(BridgeContext.java:804)
>      [exec] at org.apache.batik.bridge.PaintServer.convertURIPaint(PaintServer.java:365)
>      [exec] at org.apache.batik.bridge.PaintServer.convertPaint(PaintServer.java:273)
>      [exec] at org.apache.batik.bridge.PaintServer.convertFillPaint(PaintServer.java:242)
>      [exec] at org.apache.batik.bridge.PaintServer.convertFillAndStroke(PaintServer.java:160)
>      [exec] at org.apache.batik.bridge.SVGShapeElementBridge.createShapePainter(SVGShapeElementBridge.java:117)
>      [exec] at org.apache.batik.bridge.SVGRectElementBridge.createShapePainter(SVGRectElementBridge.java:153)
>      [exec] at org.apache.batik.bridge.SVGShapeElementBridge.buildGraphicsNode(SVGShapeElementBridge.java:91)
>      [exec] at org.apache.batik.bridge.GVTBuilder.buildGraphicsNode(GVTBuilder.java:224)
>      [exec] at org.apache.batik.bridge.GVTBuilder.buildComposite(GVTBuilder.java:171)
> {quote}
> The fix is to compose the base URL and the fragment into a ParsedURLData:
> In the {{ParsedURLDataProtocolHandler}} the method:
> {code:java}
>   public ParsedURLData parseURL(ParsedURL baseURL, String urlStr) {
>         // No relative form...
>         return parseURL(urlStr);
>     }
> {code}
> should change to:
> {code:java}
>   public ParsedURLData parseURL(ParsedURL baseURL, String urlStr) {
>        if (urlStr.startsWith("#")) {
>           // Use the base, it contains the encoded document
>           ParsedURLData parseURL = parseURL(baseURL.toString());
>           // .. and pass the reference
>           parseURL.ref = urlStr.substring(1); // Skip the #
>           return parseURL;
>         } else {
>           // No relative form...
>           return parseURL(urlStr);
>         }
>   }
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]