[prev in list] [next in list] [prev in thread] [next in thread] 

List:       batik-dev
Subject:    [Bug 54059] New: ParsedURL fails using "data:" URI scheme when data contains style sheet including #
From:       bugzilla () apache ! org
Date:       2012-10-28 16:26:02
Message-ID: bug-54059-30099 () https ! issues ! apache ! org/bugzilla/
[Download RAW message or body]

https://issues.apache.org/bugzilla/show_bug.cgi?id=54059

          Priority: P2
            Bug ID: 54059
          Assignee: batik-dev@xmlgraphics.apache.org
           Summary: ParsedURL fails using "data:" URI scheme when data
                    contains style sheet including #-character
          Severity: normal
    Classification: Unclassified
                OS: Linux
          Reporter: gerber@slf.ch
          Hardware: PC
            Status: NEW
           Version: 1.8
         Component: SVG Rasterizer
           Product: Batik

Transcoder allows to pass a user style sheet uri an a hint.
Passing an data uri, such as "data:text/css;charset=UTF-8, .g { display:none;}"
works as expected. But as soon, as the data (style sheet) contains a
#-character, the style sheet can not be parsed correctly any more. 
The reason for this is in the ParsedULR class (or a class used by it -
ParsedURLDataProtocolHandler:parseURL(String urlStr)) because the  # character
is interpreted as a URL fragment separator, not considering the used URI schema
at all. As far as i know is the syntax for data URI's
"data:<mediatype>[;base64],<data>". Because of this, the part after the first
#-character is taken as URI fragment and is no longer part of the style sheet,
resulting in an exception like this:

org.w3c.dom.DOMException: data:text/css;charset=UTF-8,#RestrictedAreas {
display:none;}:
Invalid CSS document.
java.lang.NullPointerException
    at
org.apache.batik.css.engine.CSSEngine.parseStyleSheet(CSSEngine.java:1184)
    at
org.apache.batik.css.engine.CSSEngine.parseStyleSheet(CSSEngine.java:1125)
    at
org.apache.batik.bridge.BridgeContext.initializeDocument(BridgeContext.java:386)
    at org.apache.batik.bridge.GVTBuilder.build(GVTBuilder.java:55)
    at
org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(SVGAbstractTranscoder.java:208)
    at
org.apache.batik.transcoder.image.ImageTranscoder.transcode(ImageTranscoder.java:92)
    at
org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(XMLAbstractTranscoder.java:142)
    at
org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(SVGAbstractTranscoder.java:156)

Reproduce:
Passing an URI as "data:text/css;charset=UTF-8,#RestrictedAreas {
display:none;}" as a user-stylsheet-uri to the transcoder hints.

Workaround: 
a) Use a file instead of encoding data directly in the URL 
b) Encode style sheet data using based64

String stylesheet = "#RestrictedAreas { display:none;}"
Charset charset = Charset.forName("UTF-8");
byte[] styleSheetBytes =
Base64.encodeBase64(charset.encode(stylesheet).array());
CharBuffer styleSheet  = charset.decode(ByteBuffer.wrap(styleSheetBytes));
String dataURL = "data:text/css;base64,"+styleSheet;
hints.put(ImageTranscoder.KEY_USER_STYLESHEET_URI, dataURL);

regards

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-dev-help@xmlgraphics.apache.org

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic